xcode ios 9 和 NSAppTransportSecurity
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32663122/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ios 9 and NSAppTransportSecurity
提问by Maxim Zakopaylov
There is a problem with iOS 9 and work with the server. I info.plist set:
iOS 9 存在问题并使用服务器。我 info.plist 设置:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
When you run the application through Xcode, everything is fine. Work with the server takes place perfectly. But as soon as I stop the application and try to run it by simply clicking on the icon in the simulator. The network stops working. The same problem when I send the application to the Review in TestFlight. The application is installed, but the network stops working again.
当您通过 Xcode 运行应用程序时,一切正常。与服务器的工作完美地进行。但是一旦我停止应用程序并尝试通过单击模拟器中的图标来运行它。网络停止工作。当我将应用程序发送到 TestFlight 中的 Review 时,同样的问题。应用程序已安装,但网络再次停止工作。
Xcode 7.0 (7a220) iOS 9.0
Xcode 7.0 (7a220) iOS 9.0
采纳答案by makaron
Are you sure it's not working? I tested it and everything is fine.
你确定它不起作用?我测试了它,一切都很好。
Possible actions:
可能的操作:
Having a Debug mode enabled, build your app, run it from Xcode and make sure that you don'tget an App Transport Securityerror:
启用调试模式,构建您的应用程序,从 Xcode 运行它并确保您没有收到应用程序传输安全错误:
App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure.
App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure.
when launching it from Xcode using your simulator. Now find a DEVICE_CODEof the same very simulator
使用模拟器从 Xcode 启动它时。现在找到同一个模拟器的DEVICE_CODE
(Hint: it will be one of these ~/Library/Developer/CoreSimulator/Devices/. The easiest way to find this code from Xcode is to go Window->Devices)
(Hint: it will be one of these ~/Library/Developer/CoreSimulator/Devices/. The easiest way to find this code from Xcode is to go Window->Devices)
and open with Consoleits log file:
并使用控制台打开其日志文件:
~/Library/Logs/CoreSimulator/<DEVICE_CODE>/system.log
Clear the history (just in case you can launch your app from Xcode once again and make sure your output is getting into the log-file you opened, and that you still don't get App Transport Securityerror in there).
清除历史记录(以防万一您可以再次从 Xcode 启动您的应用程序,并确保您的输出进入您打开的日志文件,并且您仍然没有在其中收到应用程序传输安全错误)。
Now launch your app from the simulator and check if you have any errors related to App Transport Securityin the log.
现在从模拟器启动您的应用程序并检查日志中是否有与应用程序传输安全相关的任何错误。
For me I don't have any if none of them I get when working from Xcode.
对我来说,如果我从 Xcode 工作时没有得到任何的话,我就没有。
==================================
==================================
P.S.:
附注:
It's strongly recommended to not set an NSAllowsArbitraryLoadsto true, you'd rather want to achieve the desired result with:
强烈建议不要将NSAllowsArbitraryLoads设置为true,您希望通过以下方式实现所需的结果:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>yourserver.com</key>
<dict>
<!--Include to allow subdomains-->
<key>NSIncludesSubdomains</key>
<true/>
<!--Include to allow HTTP requests-->
<key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
<true/>
<!--Include to specify minimum TLS version-->
<key>NSTemporaryExceptionMinimumTLSVersion</key>
<string>TLSv1.1</string>
</dict>
</dict>
</dict>
回答by Grigori Jlavyan
It should be done like this, you need to add in your Plist the following records Apple Documentation
应该这样做,你需要在你的 Plist 中添加以下记录 Apple 文档
It is lazy so your frameworks have access to Internet
它是懒惰的,因此您的框架可以访问 Internet
NSAppTransportSecurity <- Type Dictionary
NSAppTransportSecurity <- 类型字典
NSAllowsArbitraryLoads <- Type Boolean Value YES
NSAllowsArbitraryLoads <- 类型布尔值是
回答by DILIP KOSURI
Its very simple, just follow the below steps:
它非常简单,只需按照以下步骤操作:
- App Transport security settings.
- Allow Arbitrary loads.
- Exception domains and the domain/host reference.
- 应用传输安全设置。
- 允许任意加载。
- 异常域和域/主机引用。
Note: This issue happens because your project settings does not allow by default any cross site scripting references. Hence, it blocks any service calls that goes outside of your app.
注意:发生此问题是因为您的项目设置默认不允许任何跨站点脚本引用。因此,它会阻止任何超出您的应用程序的服务调用。