Apple 无法识别 imgur 的 HTTPS [英] Apple doesn't recognize imgur's HTTPS

查看:17
本文介绍了Apple 无法识别 imgur 的 HTTPS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have multiple links from imgur with HTTPS (e.g https://i.imgur.com/DMKPbRe.jpg). I'm using this as one of my background for my protoype app, but whenever I run it on my iPhone 7 physical device, the app crushes with error code 1200. Actual error is below:

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,因为我不想破坏 Apple 在 Xcode 中开发的应用程序的安全性

I don't want to turn off App Transport Security as I don't want to possibly mess up Apple's security for apps developed in Xcode

推荐答案

我在另一台服务器上发现了类似的问题,并遵循了@Mats 的建议/评论,我使用 nscurl 发现了服务器所做的不支持 TLS 1.3 并且经过反复试验,NSExceptionRequiresForwardSecrecy 也不支持.因此,我在我的项目 Info.plist 中添加了以下内容:

I found a similar problem with another server, and following the advice/comment of @Mats I found with nscurl that the server does not support TLS 1.3 and with trial and error that NSExceptionRequiresForwardSecrecy is not supported, too. Therefore, I added the following to my project 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> 其中定义了受这些设置影响的域,不会应用于任何其他域.

Pay special attention to <key>rovicorp.com</key> where is defined the domain affected by these settings, which will not be applied to any other domains.

NSTemporaryExceptionAllowsInsecureHTTPLoads 是可以去掉的,我只是加了它来完成,以防万一有人想使用 HTTP 请求.

The NSTemporaryExceptionAllowsInsecureHTTPLoads can be removed, I just added it for completion, just in case that someone wants to use HTTP requests.

希望对你有帮助

哈维

这篇关于Apple 无法识别 imgur 的 HTTPS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆