使用Xcode7運(yùn)行iOS9應(yīng)用時(shí),如果獲取 http:// 數(shù)據(jù)時(shí)會報(bào)如下錯(cuò)誤:
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é)議碗旅,解決辦法如下,修改項(xiàng)目的 Info.plist 文件镜悉,增加以下內(nèi)容:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
如果覺得直接修改文件太麻煩祟辟,可以在項(xiàng)目的 Info 直接通過界面添加配置:
在 Info 中添加 NSAppTransportSecurity 類型 Dictionary ;
在 NSAppTransportSecurity 下添加 NSAllowsArbitraryLoads 類型 Boolean ,值設(shè)為 YES ;