【发布时间】: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 而编写的任何代码。它真的可以帮助其他人重现问题,以便对其进行诊断。