今天升級Xcode 7.0 bata
發現網絡訪問失敗。
輸出錯誤信息
<code style="padding: 0px; color: inherit; white-space: inherit; background-color: transparent;"><span style="font-family:Comic Sans MS;font-size:18px;">The resource could not be loaded because the App Transport Security policy requires the <span class="hljs-operator"><span class="hljs-keyword" style="color: rgb(133, 153, 0);">use</span> <span class="hljs-keyword" style="color: rgb(133, 153, 0);">of</span> a secure <span class="hljs-keyword" style="color: rgb(133, 153, 0);">connection</span>.
</span></span></code>
Google後查證,iOS9引入了新特性App Transport Security (ATS)
。詳情:App
Transport Security (ATS)
新特性要求App內訪問的網絡必須使用HTTPS
協議。
但是現在公司的項目使用的是HTTP
協議,使用私有加密方式保證數據安全。現在也不能馬上改成HTTPS
協議傳輸。
最終找到以下解決辦法:
- 在Info.plist中添加
NSAppTransportSecurity
類型Dictionary
。 - 在
NSAppTransportSecurity
下添加NSAllowsArbitraryLoads
類型Boolean
,值設爲YES