Search code examples
javascriptiosgoogle-mapsapp-transport-security

NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9814) in Loading webview?


I have a url which domain.com/map.jsp this is a JSP page which shows the google map with custom markers for that some javascript code is written.When i load this page on device then it shows me error as NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9814).but it works fine on iOS simulator.

I have searched a lot about this on google but no solution worked.

1.Bye passing the url

<key>NSAppTransportSecurity</key>
    <dict>
        <key>NSAllowsArbitraryLoads</key>
        <true/>
    </dict>

2.Specifying the url only.I can't hard code the url because url can be dynamic so below code will not work for me.

<key>NSAppTransportSecurity</key>
<dict>
  <key>NSExceptionDomains</key>
  <dict>
    <key>yourdomain.com</key>
    <dict>
      <!--Include to allow subdomains-->
      <key>NSIncludesSubdomains</key>
      <true/>
      <!--Include to allow HTTP requests-->
      <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
      <true/>
      <!--Include to specify minimum TLS version-->
      <key>NSTemporaryExceptionMinimumTLSVersion</key>
      <string>TLSv1.1</string>
    </dict>
  </dict>
</dict>

3.I have added below methods in mywebview class but none of the methods gets called

-(BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:
(NSURLProtectionSpace *)protectionSpace {
    return YES;
}

-(void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:
(NSURLAuthenticationChallenge *)challenge {
    if (([challenge.protectionSpace.authenticationMethod
          isEqualToString:NSURLAuthenticationMethodServerTrust])) {
        if ([challenge.protectionSpace.host isEqualToString:@"mydomain.com"]) {
            NSLog(@"Allowing bypass...");
            NSURLCredential *credential = [NSURLCredential credentialForTrust:
                                           challenge.protectionSpace.serverTrust];
            [challenge.sender useCredential:credential
                 forAuthenticationChallenge:challenge];
        }
    }
    [challenge.sender continueWithoutCredentialForAuthenticationChallenge:challenge];
}

Please suggest why it not working on iOS device but it is working fine on simulator.What is the solution?


Solution

  • It was issue with date/time settings of my iPad.Firstly i tried opening google.com on chrome on iPad then it was showing unsecure network error.So i changed the iPad date/time settings my issue was resolved.