我在使用 iOS 9 sdk 的 XCode 7 中使用 WKWebView 时遇到问题。由于某种原因,我尝试加载的网站有一半显示为空白(例如移动 Facebook)。
当我在 iOS 8 上构建应用程序时,WKWebView 工作得很好。我没有更改任何用于加载网页的代码(我使用了带有 nsurl 的 loadrequest),而且我知道 webview 是事件的,因为某些链接确实加载了。
这可能是一个错误吗?
最佳答案
这可能与 iOS 9 中引入的名为 ATS(应用程序传输安全)的新功能有关。
请参阅: https://developer.apple.com/library/prerelease/ios/technotes/App-Transport-Security-Technote/
All connections using the NSURLConnection, CFURL, or NSURLSession APIs use App Transport Security default behavior in apps built for iOS 9.0 or later, and OS X 10.11 or later. Connections that do not follow the requirements will fail.
可以添加异常(exception)或允许任何非安全连接。例如,您可以将其添加到 Info.plist:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
关于swift2 - iOS 9 中的 WKWebView 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32669837/