苹果无法识别imgur的HTTPS

时间:2019-01-22 11:50:48

标签: ios swift xcode

我有来自imgur和HTTPS的多个链接(例如https://i.imgur.com/DMKPbRe.jpg)。我将此作为我的原型应用程序的背景之一,但是每当我在iPhone 7物理设备上运行该应用程序时,该应用程序都会崩溃,错误代码为1200。实际错误如下:

2019-01-22 19:36:54.402391+0800 App[00000:0000000] Task <00000000000000000000>.<2> load failed with error Error Domain=NSURLErrorDomain Code=-1200 "An SSL error has occurred and a secure connection to the server cannot be made." UserInfo={NSErrorFailingURLStringKey=https://i.imgur.com/DMKPbRe.jpg, NSLocalizedRecoverySuggestion=Would you like to connect to the server anyway?, _kCFStreamErrorDomainKey=3, _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <00000000000000000>.<2>, _NSURLErrorRelatedURLSessionTaskErrorKey=(
"LocalDataTask <0000000000000>.<2>"), NSLocalizedDescription=An SSL error has occurred and a secure connection to the server cannot be made., NSErrorFailingURLKey=https://i.imgur.com/DMKPbRe.jpg, NSUnderlyingError=0x2824d4150 {Error Domain=kCFErrorDomainCFNetwork Code=-1200 "(null)" UserInfo={_kCFStreamPropertySSLClientCertificateState=0, _kCFNetworkCFStreamSSLErrorOriginalValue=-9816, _kCFStreamErrorDomainKey=3, _kCFStreamErrorCodeKey=-9816}}, _kCFStreamErrorCodeKey=-9816} [-1200]

用于检索网址的代码:

let imgURL = URL(string: "https://i.imgur.com/DMKPbRe.jpg")
    let imgImageView = UIImageView()
    imgImageView.kf.setImage(with: imgURL) { (img, err, cacheType, url) in
        if img == nil {
           // TODO: add placeholder image when url didn't loaded
        }
        let imgTexture = SKTexture(image: img!)
        self.img = SKSpriteNode(texture: imgTexture)
    }

我不想关闭App Transport Security,因为我不想破坏苹果使用Xcode开发的应用程序的安全性

1 个答案:

答案 0 :(得分:2)

我在另一台服务器上发现了类似的问题,并且按照我在nscurl中发现的@Mats的建议/评论,该服务器不支持TLS 1.3,并且反复试验还不支持NSExceptionRequiresForwardSecrecy。因此,我在项目Info.plist中添加了以下内容:

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSExceptionDomains</key>
    <dict>
        <key>rovicorp.com</key>
        <dict>
            <!-- Allow subdomains -->
            <key>NSIncludesSubdomains</key>
            <true/>
            <!-- Exclude HTTP requests -->
            <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
            <false/>
            <!-- Disable some extra cypher suites -->
            <key>NSExceptionRequiresForwardSecrecy</key>
            <false/>
            <!-- Specify minimum TLS version -->
            <key>NSTemporaryExceptionMinimumTLSVersion</key>
            <string>TLSv1.2</string>
        </dict>
    </dict>
</dict>

请特别注意<key>rovicorp.com</key>,其中定义了受这些设置影响的域,该域将不会应用于任何其他域。

NSTemporaryExceptionAllowsInsecureHTTPLoads可以删除,我只是为了完成而添加了它,以防万一有人要使用HTTP请求。

希望这对您有帮助,

Xavi