Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSURLConnection finished with error - code -1022

Tags:

ios

webview

Guys i try to learn webview it can't load give me error like:

NSURLConnection finished with error - code -1022

- (void)viewDidLoad {
        [super viewDidLoad];
        NSString *urlString = @"http://www.sourcefreeze.com";
        NSURL *url = [NSURL URLWithString:urlString];
        NSURLRequest *request = [NSURLRequest requestWithURL:url];
        [_webView loadRequest:request];

    }
like image 949
Gangani Roshan Avatar asked Dec 18 '17 09:12

Gangani Roshan


3 Answers

I think it is about App Transport Security.Because your url is not https.Try to change like this in the info.plist file

<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
like image 52
EricZhao Avatar answered Nov 02 '22 05:11

EricZhao


You are getting this error because you are not using https url. To fix follow below steps:

  • Right click on info.plist file.
  • Open As Source code.
  • Add below line just before /dict:

    <key>NSAppTransportSecurity</key>
    <dict>
        <key>NSAllowsArbitraryLoads</key>
        <true/>
    </dict>
    
like image 39
iVarun Avatar answered Nov 02 '22 05:11

iVarun


I was having a similar issue,

NSURLConnection finished with error - code -1200

I was trying to reach a blocked port in my company. Changing the port let me connect normally.

As pointed out below, disabling Firewall could also solve the issue.

like image 2
Onat Korucu Avatar answered Nov 02 '22 05:11

Onat Korucu