2

When I open a link in UIWebView and click on facebook icon of content of that URL it gives the following error

2014-01-09 13:15:14.412 AppName[2067:5407] CFNetwork SSLHandshake failed (-108)
2014-01-09 13:15:14.412 AppName[2067:5407] CFNetwork SSLHandshake failed (-108)
2014-01-09 13:15:15.063 AppName[2067:5407] CFNetwork SSLHandshake failed (-108)
2014-01-09 13:15:15.064 AppName[2067:5407] NSURLConnection/CFURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -108)

I also search this error in google But no result found for -108. results found for 98*

and this same link same process works in safari and also in other app UIWebView. but I take new project for second app and put this link in UIWebView, It gives error.

Please Help and Thanks in Advance.

DharaParekh
  • 1,730
  • 1
  • 10
  • 17

3 Answers3

10

If you put this anywhere in your code the app will bypass certificate validation:

@implementation NSURLRequest(DataController)

+(BOOL)allowsAnyHTTPSCertificateForHost:(NSString *)host
{
return YES;
}

@end
alexandrubarbat
  • 197
  • 1
  • 4
3

Facebook have https protocol in URL.

Loading a https url in UIWebview in different from loading the normal https url.

And to load https URL please have a look at loading-https-url-in-uiwebview and this SO Post 1 and SO Post 2 here.

It may help you.

Community
  • 1
  • 1
Rahul Patel
  • 5,858
  • 6
  • 46
  • 72
-1

I think you are trying to find this:

BOOL _Authenticated;
NSURLRequest *_FailedRequest;
#pragma UIWebViewDelegate

-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request   navigationType:(UIWebViewNavigationType)navigationType {
    BOOL result = _Authenticated;
    if (!_Authenticated) {
        _FailedRequest = request;
        NSURLConnection *urlConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
        [urlConnection start];
    }
    return result;
}

#pragma NSURLConnectionDelegate

-(void)connection:(NSURLConnection *)connection willSendRequestForAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {
    if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]) {
        NSURL* baseURL = [NSURL URLWithString:@"your url"];
        if ([challenge.protectionSpace.host isEqualToString:baseURL.host]) {
            NSLog(@"trusting connection to host %@", challenge.protectionSpace.host);
            [challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge];
        } else
            NSLog(@"Not trusting connection to host %@", challenge.protectionSpace.host);
    }
    [challenge.sender continueWithoutCredentialForAuthenticationChallenge:challenge];
}

-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)pResponse {
    _Authenticated = YES;
    [connection cancel];
    [webvw loadRequest:_FailedRequest];
}
Manab Kumar Mal
  • 20,788
  • 5
  • 31
  • 43