使用Xcode7運行iOS9應(yīng)用時,如果獲取 http:// 數(shù)據(jù)時會報如下錯誤:
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.
原因:從iOS9起,新特性要求App訪問網(wǎng)絡(luò)請求,要采用 HTTPS 協(xié)議。
如果仍想要使用HTTP協(xié)議,解決辦法如下,修改項目的 Info.plist 文件,增加以下內(nèi)容:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
如果覺得直接修改文件太麻煩,可以在項目的 Info 直接通過界面添加配置:
在 Info 中添加 NSAppTransportSecurity 類型 Dictionary ;
在 NSAppTransportSecurity 下添加 NSAllowsArbitraryLoads 類型 Boolean ,值設(shè)為 YES ;