Reputation: 736
I've created an iOS app using Cordova 3.2 and jquery mobile 1.3. I use jquery ajax to send requests to a RESTfull service to retrieve/update information.
I have a number of test devices, various iPhones, with various different iOS versions. On an iPhone 4S, running iOS 7 I receive the following error when any ajax request is sent:
NSURLConnection/CFURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9813)
This only happens on this device, on another iPhone 4S, also running iOS 7, it works absolutely fine, as it does on all of the other test devices I'm using.
I've read that this indicates the certificate is invalid in someway, that being the case, can this be ignored and why would affect on one device?
Can anyone suggest why this might be happening and what could be different about the device that would prevent it from working only on one of my devices. Thanks
Upvotes: 18
Views: 30533
Reputation: 21
Xcode 7.3 Swift 2.2
To get this to work I had to do 3 things:
Upvotes: 2
Reputation: 489
The Swift version of Markivs answer (taken from here):
extension NSURLRequest {
static func allowsAnyHTTPSCertificateForHost(host: String) -> Bool {
return true
}
}
Upvotes: 2
Reputation: 721
I got the same issue while running the application in simulator .the reason behind this is there is no trusted certificate in the simulator.
simply drag & drop your .cer Files into your running Simulator window. You'll see Safari flashing and then the import dialog for your Certificate (or Certificate Authority)...
Upvotes: 1
Reputation: 7387
If it's working on some devices and not others, there's some difference in the certificate validation parameters for those devices. Here are some things to look at:
If you access your endpoint URL in the browser on the unhappy device, what error does it give you? (Note: obviously your server will give you some error as well because you aren't requesting with the right headers and params. I'm talking about Safari itself, though - it should give a more detailed message about what (it thinks) is wrong with the certificate.)
*Edited to correct something I misremembered: you do not have the option to accept the leaf certificate if you go to the URL in Safari, you only have the option to accept intermediate certificates if you attempt to load them directly.
Upvotes: 12
Reputation: 479
I had a similar issue, but in my case, across all devices this used to happen and only during an ajax call with https.
If that is your case, adding the below code at the end of appDelegate.m file will mitigate your issue.
@implementation NSURLRequest(DataController)
+ (BOOL)allowsAnyHTTPSCertificateForHost:(NSString *)host
{
return YES;
}
@end
But i do doubt that if it is working in other devices, the solution i have given, might not be effective. But do give it a try.
Upvotes: 33