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
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.
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.
The Swift version of Markivs answer (taken from here):
extension NSURLRequest {
static func allowsAnyHTTPSCertificateForHost(host: String) -> Bool {
return true
}
}
Xcode 7.3 Swift 2.2
To get this to work I had to do 3 things:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With