I'm trying to connect my iOS app to an HTTPS Rails app which is currently run on a local host in my network. I can access the site from my browser with https://myIP:3000/display
as well as in the command line with a curl request. I'm trying to access it from my app using:
class FirstViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
//let url = NSURL(string: "https://another/Sinatra/website/feed")
let url = NSURL(string: "https://myIP:3000/display")
let request = NSURLRequest(URL: url!)
let task = NSURLSession.sharedSession().dataTaskWithURL(url!)
task!.resume()
}
When I try to access the sinatra website I have no trouble and can even print out the JSON to the console with the correct commands. However, when I set url to my Rails website I get the following error.
NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9813)
In addition, I can tell that my localhost Rails app (on the other machine) is not pinged from the iOS app, but is pinged from the browser and curl command.
Any ideas how to fix this?
(Edit - I misread this as 9814, expired cert. I'm not sure how to solve this one, but hopefully my response helps point in the right direction.)
Looks like a cert issue different from the usual "Allow Arbitrary Loads" question.
Brief excerpt from: Apple Documentation - Appendix A: Common Server Trust Evaluation Errors
NSOSStatusErrorDomain errSSLNoRootCert -9813
This is the only solution worked for me... At the end of your AppDelegate.m file, insert the code:
Thanks for jc ivancevich article http://ivancevich.me/articles/ignoring-invalid-ssl-certificates-on-cordova-android-ios/
try change the session variable, this change help me
Modifying the info.plist worked for me as well.
If I understood well, Apple now wants the developers to use HTTPS and TLS 1.2 for network calls.
Temporary, you can add this in your "Info.plist" file :
Just have a look to this link, it may also help you : http://ste.vn/2015/06/10/configuring-app-transport-security-ios-9-osx-10-11/
--
Update : Following some comments the above solution is not anymore working. Here is an updated solution.
Info.plist
file.Dictionary
and of KeyApp Transport Security Settings
.Boolean
, of KeyAllow Arbitrary Loads
and of ValueYES
-
Otherwise you can set
Domain Exceptions
. This is how to do :Info.plist
file.Dictionary
and of KeyApp Transport Security Settings
.Dictionary
and of KeyException Domains
.Dictionary
and of KeyThe domain
.Boolean
and of KeyNSExceptionAllowsInsecureHTTPLoads
&NSIncludesSubdomains
with Value toYES
.Links
https://forums.developer.apple.com/message/5857#5857
2015 WWDC Session 711
iOS 9 HTTP Connection Error - StackOverflow
NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9813)
Add a new row in your plist file.