Swift / https: NSURLSession / NSURLConnection Error loading HTTP

Unfortunately this morning my Xcode has been upgraded to version 7 and the iOS app I developed with http now wants https. So, following many tutorials, I set up my MAMP server to use https / ssl, creating a dummy certificate. Now in my iOS app urls are the following:

static var webServerLoginURL = "https://localhost:443/excogitoweb/mobile/loginM.php" static var webServerGetUserTasks = "https://localhost:443/excogitoweb/mobile/handleTasks.php" static var webServerGetUsers = "https://localhost:443/excogitoweb/mobile/handleUsers.php" static var webServerGetProjects = "https://localhost:443/excogitoweb/mobile/handleProjects.php" 

and they work fine if I try to access them in my browser. I was used to access the database and php files using NSURLSession.sharedSession (). DataTaskWithRequest (), which now causes an error in the header. For example, here is the line where the error occurs:

 if let responseJSON: [[String: String]] = (try? NSJSONSerialization.JSONObjectWithData(data!, options: NSJSONReadingOptions())) as? [[String: String]] { ... } 

and this is the complete error message:

 2015-09-21 16:41:48.354 ExcogitoWeb[75200:476213] CFNetwork SSLHandshake failed (-9824) 2015-09-21 16:41:48.355 ExcogitoWeb[75200:476213] NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9824) fatal error: unexpectedly found nil while unwrapping an Optional value 

I would like to know how to fix this. I read some useful answers here, but there are many things that I still do not understand, and if someone helps / explains me, I would be very grateful.

+7
ios swift2 xcode7
source share
3 answers

Add this to your Info.plist app

 <key>NSAppTransportSecurity</key> <dict> <key>NSAllowsArbitraryLoads</key> <true/> </dict> 
+9
source
 fatal error: unexpectedly found nil while unwrapping an Optional value 

usually means that you are doing something not very good, and by looking at if

 if let responseJSON: [[String: String]] = (try? NSJSONSerialization.JSONObjectWithData(data!, options: NSJSONReadingOptions())) as? [[String: String]] { 

I see that there is data! but this data object is zero. You really need to deploy options before using them, especially when working with remote data.

Then you have a network error, which is probably related to Apple's ATS added in iOS 9.

See another answer on how to temporarily disable ATS. fooobar.com/questions/19000 / ...

edit: now I see that you added ssl to your localhost, this is good. However, ATS is not enough to work, because it requires TLS 1.2, not self-signed certificates.

+3
source

Really old question, but I thought I would answer. This usually happens when you try to deploy an http object and it returns to zero.

Make sure you expand your URL and set it to the default value.

example:

 let jsonURL = "your https link to your json" guard let url = URL(string: jsonURL) else { return } // dont force unwrap 

hope this helps!

+1
source

All Articles