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

不幸的是今天早上我的XCode更新到版本7,我用http开发的iOS应用程序现在想要https.因此,在许多教程之后,我配置了我的MAMP服务器,以便使用https / ssl创建虚拟证书.现在在我的iOS应用中,URL如下所示:
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文件,现在它会引发标题中的错误.例如,这是引发错误的行:

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

这是完整的错误消息:

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中
<key>NSAppTransportSecurity</key>  
    <dict>  
    <key>NSAllowsArbitraryLoads</key>  
    <true/>  
    </dict>

以上是来客网为你收集整理的ios – Swift / https:NSURLSession / NSURLConnection HTTP加载失败全部内容,希望文章能够帮你解决ios – Swift / https:NSURLSession / NSURLConnection HTTP加载失败所遇到的程序开发问题。

如果觉得来客网网站内容还不错,欢迎将来客网网站推荐给程序员好友。