【问题标题】:Apple doesn't recognize imgur's HTTPS苹果无法识别 imgur 的 HTTPS
【发布时间】:2019-06-25 18:21:35
【问题描述】:

我有多个来自 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]

用于检索 url 的代码:

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 中开发的应用程序的安全性

【问题讨论】:

  • 请出示您用来获取图片的代码。
  • @JeremyP 我使用 Kingfisher 库来检索图像。它与 Kingfisher 无关,因为我尝试使用 Google URL 检索 Google 的徽标并且它有效。
  • 您是否尝试过使用 nscurl 进行 ATS 诊断?我认为您可以使用以下命令在 Terminal.app 中运行它:nscurl --ats-diagnostics https://i.imgur.com/DMKPbRe.jpg
  • @Mats,好像imgur 不支持TLSv1.3
  • @Akio 我的意思是向我们展示您为获取 URL 而编写的任何代码。它真的可以帮助其他人重现问题,以便对其进行诊断。

标签: ios swift xcode


【解决方案1】:

我在另一台服务器上发现了类似的问题,并且按照@Mats 的建议/评论,我发现nscurl 该服务器不支持 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>

特别注意&lt;key&gt;rovicorp.com&lt;/key&gt;,其中定义了受这些设置影响的域,不会应用于任何其他域。

NSTemporaryExceptionAllowsInsecureHTTPLoads可以去掉,我只是为了补全而添加的,以防万一有人要使用HTTP请求。

希望对你有帮助,

哈维

【讨论】:

    猜你喜欢
    • 2018-02-19
    • 2021-10-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-28
    • 1970-01-01
    • 2019-10-13
    相关资源
    最近更新 更多