ios - Swift2.0 HTTP 请求不工作

标签 ios swift xcode7

<分区>

你好 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>

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

最佳答案

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

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

enter image description here

关于ios - Swift2.0 HTTP 请求不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31655232/

相关文章:

ios - 从本地通知启动应用程序; VC实例化,但没有出现

ios - Realm swift : No such module 'RealmSwift'

ios - 无法将类型 'NSNull' (0x10aa1b600) 的值转换为 'NSString' (0x10b4dab48)

import - 如何在 Swift 中定义自定义 UIGestureRecognizer?

ios - 使用 Jenkins 和 Xcode 7 通过 TestFlight 构建 iOS 应用程序并分发 .ipa

ios - 对成员 'Int.init' 的模糊引用

iphone - 如何在允许的一百个临时安装之一上安装应用程序?

ios - 为什么 beginGeneratePlaybackNotifications 会产生错误?

swift - 用 guard 检查 nil 而不是 if?

ios - Fairplay SDK 和 IOS9