1. 程式人生 > >iOS知識---webView載入網址報錯Error Domain=NSURLErrorDomain Code=-1022 "The resource could not be loaded beca

iOS知識---webView載入網址報錯Error Domain=NSURLErrorDomain Code=-1022 "The resource could not be loaded beca

xcode在使用webView載入網頁的時候可能會遇到載入不出來的報錯問題,

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=

NSErrorFailingURLKey= http://www.baidu.com/ , 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