Reputation: 587
How to load a webpage (Https using a self signed certificate) on the UIWebView (iOS)? I tried using NSURLConnection and I am able to load the NSMutableData to the UIwebView. But in this case I am not able to see the images in that page.
Upvotes: 0
Views: 1817
Reputation: 1399
Self signed certificates most of the time can not be validated by client, thats why the client can not load the data, because it can not validate from server.
Certificates uses domains to validate itself so it is a bit hard to have on development environment.
There is a tool which creates for local environment certificate, i am not sure how it is internally working my best thought is it adds another CA file on your environment.
You may want to check mkcert it is very easy to use nice workaround.
Upvotes: 0
Reputation: 6268
[yourWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"yourUrlGoesHere"]]];
And about the certificates part if your URL openable in Safari it will open in a webview.
Update for the comment
Try the below
NSURLRequest *req = [NSURLRequest requestWithURL:[NSURL URLWithString:@"yourUrlGoesHere"]];
NSURLConnection *urlConnection=[NSURLConnection connectionWithRequest:req delegate:self];
[yourWebView loadRequest:req];
and implement the following delegate methods in your class,
#pragma mark - NSURLConnection Delegate Methods
- (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace {
return [protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust];
}
- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {
[challenge.sender continueWithoutCredentialForAuthenticationChallenge:challenge];
}
Upvotes: 1