ios – Swift / https:NSURLSession / NSURLConnection HTTP加载失败

前端之家收集整理的这篇文章主要介绍了ios – Swift / https:NSURLSession / NSURLConnection HTTP加载失败前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
不幸的是今天早上我的XCode更新到版本7,我用http开发的iOS应用程序现在想要https.因此,在许多教程之后,我配置了我的MAMP服务器,以便使用https / ssl创建虚拟证书.现在在我的iOS应用中,URL如下所示: @H_301_2@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"

如果我尝试在浏览器中访问它们,它们工作正常.
我习惯使用NSURLSession.sharedSession().dataTaskWithRequest()来访问数据库PHP文件,现在它会引发标题中的错误.例如,这是引发错误的行:

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

这是完整的错误消息:

@H_301_2@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

我想知道如何解决这个问题.我在这里已经阅读了一些有用的答案,但有许多事情我仍然不明白,如果有人愿意帮助/解释我,我将非常感激.

解决方法

将其添加到您应用的Info.plist中 @H_301_2@<key>NSAppTransportSecurity</key> <dict> <key>NSAllowsArbitraryLoads</key> <true/> </dict>

猜你在找的iOS相关文章