Swift2.0 HTTP请求无效

时间:2015-07-27 14:01:36

标签: ios swift xcode7

Hello Stackoverflow,

我将swift应用程序移动到Swift2.0后,我一直收到此错误:

App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app's Info.plist file.
The resource could not be loaded because the App Transport Security policy requires the use of a secure connection.

我看了以下链接https://forums.developer.apple.com/thread/5835

并将以下代码添加到我的info.plist

    <key>NSAppTransportSecurity</key>
<dict>
        <key>NSAllowsArbitraryLoads</key>
        <true/>
        <key>NSExceptionDomains</key>
        <dict/>
</dict>

它仍然不起作用,任何人都有替代解决方案吗?

1 个答案:

答案 0 :(得分:8)

它不是Swift 2.0问题,实际上是iOS 9.0问题,其中iOS 9.0会强制网络流量超过https设置以下标记,允许http流量。

您必须在.plist文件中的NSAppTransportSecurity字典下将NSAllowsArbitraryLoads键设置为YES。希望这有帮助!

enter image description here