在做一個網絡應用時,解析json時報錯 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. fatal error: unexpectedly found nil while unwrapping an Optional value
報錯原因是xcode禁止明文http傳輸.通過修改info.plist可解決:
- 添加App Transport Security Settings,類型是Dictionary
- 在App Transport Security Settings添加Allow Arbitrary Loads,類型是Boolean,值是YES
Paste_Image.png
不過從蘋果官方目前發布出來的消息上看, 在 2017 年一月份開始,就不再允許開發者打開 NSAllowsArbitraryLoads 設置了。