2017-06-22 40 views
0

我试图使用SSL将URL图像下载到GMSTileLayer。NSURLSession/NSURLConnection尝试使用Alamofire下载图像时HTTP加载失败

GMSTileLayer包含加载瓷砖到谷歌地图层的委托方法:

override func requestTileFor(x: UInt, y: UInt, zoom: UInt, receiver: GMSTileReceiver) { 
    let url = URL(string: "\(urlPrefix)x=\(x)&y=\(y)&z=\(zoom)&is2d=t") 
    let zoom = UInt((self.map?.camera.zoom)!) 

    Alamofire.request(url!).responseImage { response in 
     if let image = response.result.value { 
      receiver.receiveTileWith(x: x, y: y, zoom: zoom, image: image) 
     } 
    } 
} 

当这个函数被调用时,我收到以下错误信息:

2017-06-22 09:55:49.192 PPGaugeApp[78556:4886424] NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9801) 
2017-06-22 09:55:49.274328-0400 PPGaugeApp[78556:4886488] [] nw_coretls_read_one_record tls_handshake_process: [-9801] 

我已核实通过在浏览器中测试,网址正在返回图片。

在研究这个错误,几乎所有的职位的建议作出一些改变的plist在包括minumum如下:

NSAllowsArbitraryLoads 

我当前的plist设置如下:

<key>NSAppTransportSecurity</key> 
<dict> 
    <key>NSAllowsArbitraryLoads</key> 
    <true/> 
    <key>NSExceptionDomains</key> 
    <dict> 
     <key>someDomain.com</key> 
     <dict> 
      <key>NSIncludesSubdomains</key> 
      <true/> 
      <key>NSExceptionAllowsInsecureHTTPLoads</key> 
      <true/> 
      <key>NSExceptionRequiresForwardSecrecy</key> 
      <true/> 
      <key>NSExceptionMinimumTLSVersion</key> 
      <string>TLSv1.2</string> 
      <key>NSThirdPartyExceptionAllowsInsecureHTTPLoads</key> 
      <false/> 
      <key>NSThirdPartyExceptionRequiresForwardSecrecy</key> 
      <true/> 
      <key>NSThirdPartyExceptionMinimumTLSVersion</key> 
      <string>TLSv1.2</string> 
      <key>NSRequiresCertificateTransparency</key> 
      <false/> 
     </dict> 
    </dict> 
</dict> 

plist中没有任何内容似乎对此错误消息有任何影响。我们的应用中的其他课程使用https进行身份验证,但是这是我们通过https url下载文件的唯一地方。

还有其他地方我们应该检查吗?谢谢!

回答

1

由于一些百分比转义字符出现在url字符串中url url会话出错了。使用下面的字符串扩展名从字符串中获取url。

extension String { 
    var getUrl: URL? { 
     let strurl = (self as NSString).addingPercentEncoding(withAllowedCharacters: NSCharacterSet.urlQueryAllowed)! 
     return URL(string: strurl) 
    } 
} 
相关问题