swift - App Transport Security 导致 Swift 2.0 应用程序崩溃

标签 swift swift2 xcode7 app-transport-security

<分区>

我几天前完成了我的应用程序,并安装了 Xcode 7,这让我很头疼,我遇到了很多问题,但设法解决了大部分问题,但是现在,当我的应用程序需要连接到互联网时我收到这个奇怪的错误 这是我记录的内容:

App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app's Info.plist file. Hempel.temp_caseinsensitive_renameAgain was compiled with optimization - stepping may behave oddly; variables may not be available.

enter image description here

enter image description here

let task = session.dataTaskWithRequest(request, completionHandler: {data, response, error -> Void in

            var strData = NSString(data: data!, encoding: NSUTF8StringEncoding)

            do {
                let json = try NSJSONSerialization.JSONObjectWithData(data!, options:NSJSONReadingOptions.MutableContainers ) as? NSDictionary
                if let parseJSON = json {
                   //THIS IS WHERE ERROR IS in other ViewController
                    var success = parseJSON["data"] as! [String: AnyObject]
                    let item = success["hempel_antifoulings"] as! [[String: AnyObject]]
                    for i in item{

                        let product = HempelAntifouling()
                        product.id =  i["id"]
                        product.name = i["name"]
                        product.imageUrl = i["image"]
                        product.subgroup = i["subgroup"]
                        let url = NSURL(string: String(stringInterpolationSegment: product.imageUrl))
                        let data = NSData(contentsOfURL: url!)
                        product.image = UIImage(data: data!)
            // AND THIS IS WHERE THE ERROR POINTS in one of the ViewController
                        self.array.append(product)
                    }

                }else{

                    let jsonStr = NSString(data: data!, encoding: NSUTF8StringEncoding)
                    print("Error could not parse JSON: \(jsonStr)")
                }
            } catch {
                // report error
            }

        })

        task.resume()

    }

附言这些代码行在两个 ViewControllers 中大部分相似,但错误是相同的

最佳答案

这是您应该在 Info.plist 中包含的示例:

screen

更多信息在这里:https://developer.apple.com/library/prerelease/ios/technotes/App-Transport-Security-Technote/

关于swift - App Transport Security 导致 Swift 2.0 应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32761636/

相关文章:

ios - 无法在 iOS 上接收来自 Firebase 3.2.0 主题的推送通知

ios - 多种类型的 segue 仍然无法移动 View Controller

ios - Swift 方法中的 Firebase "Could not find member: Value"

ios - 在 PageViewController 中进行漂亮的过渡

ios - 登录后如何使用 FBSDKLoginKit 注销?

ios - 自定义 UISilder 的拇指

ios - 关闭模态视图时如何在 UITableView 中显示数据

ios - 如何在下拉列表中添加文本字段自动建议?

ios - 在 Xcode 7 中单击 UITableView 的单元格时,详细信息 VC 的重定向不起作用

swift - 如何在 CoreData 中保存 UILocalNotifications