title: fetching an image from a https link
body: <p>I have just started learning ios development, and I am trying to get an image from website which uses ssl, when i connect to the site through a browser(laptop) there is a warning which says that the root certificate is not trusted, I am not the owner of the website, however I can fully trust it.
  My first attempt:</p>
  
  <pre><code>self.eventImage.image = [UIImage imageWithData:
  [NSData dataWithContentsOfURL:
  [NSURL  URLWithString:imageUrl]]];
  </code></pre>
  
  <p>so I get this error</p>
  
  <blockquote>
    <p>NSURLConnection/CFURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9807)</p>
  </blockquote>
  
  <p>I have tried to send users to the picture link by starting ios web browser, when they do that, they would get a message asking them if they could trust it or not, if they hit yes the image will appear, however i want the image to appear inside the application.</p>
  
  <p>I have also tried to use web view but it didn't work.</p>
  
  <p>Most of the similar questions in here suggested using this </p>
  
  <pre><code>- (BOOL)connection:(NSURLConnection *)
    connection canAuthenticateAgainstProtectionSpace: 
    (NSURLProtectionSpace *)protectionSpace {
      return NO;
      //return [protectionSpace.authenticationMethod isEqualToString:
      //         NSURLAuthenticationMethodServerTrust];
  }
  
  - (void)connection:(NSURLConnection *)
    connection didReceiveAuthenticationChallenge:
    (NSURLAuthenticationChallenge *)challenge {
       NSString *imageUri =[self.detailItem objectForKey: @"image"];
       NSArray *trustedHosts = [[NSArray alloc]initWithObjects:imageUri, nil];
       if ([challenge.protectionSpace.authenticationMethod   
           isEqualToString:NSURLAuthenticationMethodServerTrust])
          if ([trustedHosts containsObject:challenge.protectionSpace.host])
                 [challenge.sender useCredential:[NSURLCredential credentialForTrust:
                  challenge.protectionSpace.serverTrust] forAuthenticationChallenge:
                  challenge];
  
   [challenge.sender continueWithoutCredentialForAuthenticationChallenge:challenge];
  }
  </code></pre>
  
  <p>but these two methods were never called when I add them.</p>