WebView loadrequest request request error “nsurlconnection finished with error – Code – 1022”

Execute the following code

[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.bing.com"]]];

WebView didFailLoadWithError:(UIWebView *)webView didFailLoadWithError:(NSError *)error printed as follows

1 [6587:75627] NSURLConnection finished with error - code -1022
2 [6587:75574] Error Domain=NSURLErrorDomain Code=-1022 "The resource could not be loaded because the App Transport Security policy 
3 requires the use of a secure connection." UserInfo={NSUnderlyingError=0x600000641f50 
4 {Error Domain=kCFErrorDomainCFNetwork Code=-1022 "The resource could not be loaded because the App Transport Security policy requires 
5 the use of a secure connection." UserInfo={NSErrorFailingURLStringKey=http://www.bing.com/, 
6 NSLocalizedDescription=The resource could not be loaded because the App Transport Security policy requires the use of a secure connection.,
7  NSErrorFailingURLKey=http://www.bing.com/}}, NSErrorFailingURLStringKey=http://www.bing.com/, NSErrorFailingURLKey=http://www.bing.com/, 
8 NSLocalizedDescription=The resource could not be loaded because the App Transport Security policy requires the use of a secure connection.}

 
The solution is simple:
URLString must use HTTPS to request the WebView to display properly
 
But then I found out that I had to load http://localhost:8080 and then, sadly, I’m going to have to look at the mechanics, and in XCode 9 I’m going to get an error message that’s pretty obvious

The resource could not be loaded because the App Transport Security policy 

Go to Baidu ATS Policy, you can know the answer in detail, in SupportFiles-> Info.plist file to add the following attributes, there is a direct option, do not need to fill out

done!
 

Reproduced in: https://www.cnblogs.com/zhouhui231/p/8572705.html

Read More: