ios - NSURL 无法在 Web View 中加载 -9824

标签 ios swift xcode uiwebview nsurlrequest

我正在制作一个基于 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>

enter image description here

关于ios - NSURL 无法在 Web View 中加载 -9824,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39553622/

相关文章:

ios - 如何在 Swift 中将 TextField 添加到 UIAlertView

iOS - 超时失败的同步请求

ios - 滑动以显示 UICollectionView 上的其他按钮

ios - 为什么查询(DBAccess)第一次在 Id 属性中返回 nil?

ios - 使用 Swift 5.0 编译的模块无法被 Swift 4.2.1 编译器导入

iphone - 尝试使用 MPMoviePlayer 时出现链接器错误

objective-c - 将浮点值转换为 id。我怎样才能做到这一点?

android - 如何在 flutter google map 网络服务插件中获取当前位置?

ios - Zebra 打印机 iMZ320 的打印问题

ios - swift 从助手/另一个类中解雇 ViewController