iOS xcode 7網路請求錯誤failure Error Domain=NSURLErrorDomain Code=-1022 "The resource could not be loaded

iOS xcode 7網路請求錯誤failure Error Domain=NSURLErrorDomain Code=-1022 "The resource could not be loaded

在我們使用(xocde7.0)開啟以前的專案時,發現之前的專案在原來的版本上都沒有問題,在xcode7.0上網路請求部分發生了錯誤,會看到有這麼一段東西輸出在控制檯(據說7.1沒那問題);

2015-11-20 16:12:16.569 AFNetworking_(3.0)[3091:1743943] 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.
2015-11-20 16:12:16.662 AFNetworking_(3.0)[3091:1742917] failure Error Domain=NSURLErrorDomain Code=-1022 “The resource could not be loaded because the App Transport Security policy requires the use of a secure connection.” UserInfo={NSUnderlyingError=0x7fedb8e02ef0 {Error Domain=kCFErrorDomainCFNetwork Code=-1022 “(null)”}, NSErrorFailingURLStringKey=http://comment.api.163.com/api/json/post/list/new/hot/ent2_bbs/AI1O4EEK00032DGD/0/10/10/2/2, NSErrorFailingURLKey=http://comment.api.163.com/api/json/post/list/new/hot/ent2_bbs/AI1O4EEK00032DGD/0/10/10/2/2, NSLocalizedDescription=The resource could not be loaded because the App Transport Security policy requires the use of a secure connection.}

那是因為OS9讓所有的HTTP預設使用了HTTPS,原來的HTTP協議傳輸都改成TLS1.2協議進行傳輸。直接造成的情況就是App發請求的時候彈出網路無法連線。解決方法,在工程裡面的Info.plist裡面新增如下節點:
還有種新式該法
App Transport Security Settings Dictionary
Allow Arbitrary Loads Boolean Yes
這裡寫圖片描述
再次執行,即可成功執行~~~!!!