我有一部分代码在所有 iOS 版本上都能按预期工作,但在 iOS 9 上却不行:
NSData *response = [NSData dataWithContentsOfURL: [NSURL URLWithString: url] options:NSDataReadingUncached error:&error];
这是一个简单的 json 文本。
我遇到了这个错误:
Error Domain=NSCocoaErrorDomain Code=256 "The file “xxx.php” couldn’t be opened." UserInfo={NSURL=http://xxx.xxx.com/xxx/xxx.php?lang=fr}
如何将此 url 解释为文件?响应 = 无...
谢谢。
最佳答案
技术上是因为iOS9中网络NSURLSession的变化。 要解决您的问题,您需要转到应用程序的 info.plist,NSAppTransportSecurity [Dictionary] 需要将键 NSAllowsArbitraryLoads [Boolean] 设置为 YES 或使用 https 调用 url。
你可以在http://devstreaming.apple.com/videos/wwdc/2015/711y6zlz0ll/711/711_networking_with_nsurlsession.pdf?dl=1中看到更多关于iOS9网络NSURLSession的变化。
关于ios - 带有 dataWithContentsOfURL 的 Xcode 7/iOS 9 b5 很奇怪(错误?),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31903390/