1

I'm trying to connect to an ASP.NET MVC server from iOS but since I am running it locally I don't have a real certificate for it. I can browse to the HTTPS URL I am connecting to, but Simulator throws errors when connecting via my Objective-C code. How can I bypass these SSL errors? I need to test some server-side stuff based on the encoding/connections sent from the Simulator.

I have this error:

CFNetwork SSLHandshake failed (-9806) NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9806) 

I tried this:

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

But it didn't work. My logic is pretty simple, I just use your standard NSURLSessionDataTask objects:

NSURLSessionDataTask *getTask = [self.session dataTaskWithRequest:getRequest completionHandler: ^(NSData *data, NSURLResponse *response, NSError *error) { }]; 

I also tried using NSURLSessionDelegate:

self.session = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration] delegate:self delegateQueue:[NSOperationQueue mainQueue]]; 

...

- (void)URLSession:(NSURLSession *)session didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition disposition, NSURLCredential *credential))completionHandler { NSURLCredential *credential = [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust]; completionHandler(NSURLSessionAuthChallengeUseCredential, credential); } 

But didReceiveChallenge is never called...

I even tried installing the certificate in Simulator by dragging it in PLUS browsing to my server in Safari and trusting the certificate it presented, but even that didn't work.

1
  • I hope you get the solution now Commented Aug 16, 2016 at 6:07

1 Answer 1

3

Most answer prepares

First set Allow Arbitrary Loads of Value to YES

First Image

Then set NSExceptionAllowsInsecureHTTPLoads & NSIncludesSubdomains with Value to YES

enter image description here

NSURLSession "HTTP load failed kCFStreamErrorDomainSSL, -9813 ; Self signing certificate

HTTP Connection Error

NSURLSession/NSURLConnection HTTP load failed on iOS 9

For SSL error, you have to add following code in app delegate

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

NSURLConnection/CFURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9813) iOS

Can't Receive JSON Request Via HTTPS Due To Untrusted Certificate

Adding a self-signed certificate to iphone Simulator?

Finally Search results shows all answers

Sign up to request clarification or add additional context in comments.

2 Comments

For the laymen, how do you get to that screen on an iPhone? I assume it's like the Windows registry.
@EdWilliams That's the Info.plist of the app's source code.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.