今天升級Xcode 7.0 bata
發現網絡訪問失敗。
輸出錯誤信息html
The resource could not be loaded because the App Transport Security policy requires the use of a secure connection.
Google後查證,iOS9引入了新特性App Transport Security (ATS)
。詳情:App Transport Security (ATS)ios
新特性要求App內訪問的網絡必須使用HTTPS
協議。
可是如今公司的項目使用的是HTTP
協議,使用私有加密方式保證數據安全。如今也不能立刻改爲HTTPS
協議傳輸。git
最終找到如下解決辦法:
- 在Info.plist中添加
NSAppTransportSecurity
類型Dictionary
。 - 在
NSAppTransportSecurity
下添加NSAllowsArbitraryLoads
類型Boolean
,值設爲YES
參考:
- App Transport Security support aka apps on iOS 9 don't work #4560
- 711_networking_with_nsurlsession.pdf
總結:
蘋果正在加大應用安全的管控,這個舉措能夠看出蘋果對信息安全的重視,也暴露出大部分應用傳輸數據時都是未通過加密的,或使用私有方式加密,以致於蘋果開始對開發者提出要求。
私有加密雖然必定程度上是安全的,可是終究不是一個長久之計。全世界這麼多安全專家在維護HTTPS
安全,早日使用HTTPS
確保信息安全才是王道!也省去了私有加密協議的安全隱患!github