Xcode 7提示App Transport Security has blocked a cleartext HTTP (http://) resource load的解决办法

时间:2022-11-03 15:39:13

Xcode 7提示App Transport Security has blocked a cleartext HTTP (http://) resource load的解决办法

今天使用Xcode 7打开用Xcode 6开发的网络请求项目,Xcode 7 控制台提示如下: App TransportSecurity has blocked a cleartext HTTP (http://) resource load since it isinsecure. Temporary exceptions can be configured via your app's Info.plist file.

简而言之:ATS禁止了HTTP的明文传输,因为它不安全。可以修改Info.plist文件,让它临时允许明文传输。

解决办法:
在Info.plist文件中添加主Key值"NSAppTransportSecurity", Type为"Dictionary",

再添加次Key值"NSAllowsArbitraryLoads", Type 为"Boolean",“Value”为“YES”即可。

在info.plist中添加代码实现为

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

注:Arbitrary 英[ˈɑ:bɪtrəri] 随意的,任性的,随心所欲的; 主观的,武断的;

修改info.plist文件中可视化操作:

Xcode 7提示App Transport Security has blocked a cleartext HTTP (http://) resource load的解决办法