我正在制作一个基于 isbn 返回书评的应用程序。我试图在 Web View 中加载 Goodreads 评论小部件,但出现两个错误:
CFNetwork SSLHandshake 失败 (-9824)
和 NSURLSession/NSURLConnection HTTP 加载失败 (kCFStreamErrorDomainSSL, -9824)
我已经尝试了其他几个 url 并得到了相同的结果。
这是我调用 url 的代码:
override func viewDidLoad() {
super.viewDidLoad()
let url = NSURL (string: "https://www.goodreads.com/api/index#book.show_by_isbn");
let requestObj = NSURLRequest(URL: url!);
webView.loadRequest(requestObj);
}
在 info.plist 中,我在异常域字典中有一个 goodreads.com
字典。我在 goodreads.com 中包含 NSIncludesSubdomains、NSExceptionsAllowsInsecureHTTPLoads 和 NSExceptionsMinimumTLSVersion
(设置为 TLSv1.1)
有什么明显的错误吗?是不是域名错了?
编辑:对于后来阅读本文的任何人,我想我已经解决了。此页面 ( Does App Store reject submission if NSAllowsArbitraryLoads set to YES?) 提供了极大的帮助。
如果您使用 NSAllowsArbitraryLoads
,App Store 将拒绝您的应用。但是,它们将允许 NSAllowsArbitraryLoadsInWebContent
根据 Apple 开发者指南,
"Set this key’s value to YES to obtain exemption from ATS policies in your app’s web views, without affecting the ATS-mandated security of your NSURLSession connections. To support older versions of iOS and macOS (older than iOS 10), you can employ this key and still manually configure ATS. To do so, set this key’s value to YES and also configure the NSAllowsArbitraryLoads subways. If you add this key to your Info.plist file, then, irrespective of the value of the key, ATS ignores the value of the NSAllowsArbitraryLoads key."
最佳答案
尝试在您的 project.plist 中添加 NSAppTransportSecurity 并检查您的 url 请求是否有效。
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
关于ios - NSURL 无法在 Web View 中加载 -9824,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39553622/