应用传输安全崩溃 Swift 2.0 应用
App Transport Security crashes Swift 2.0 app
我几天前完成了我的应用程序,并安装了 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.
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()
}
P.S。这些代码行在两个 ViewControllers 中大多相似,但错误是相同的
这是您在 Info.plist
中应该拥有的示例:
更多信息在这里:https://developer.apple.com/library/prerelease/ios/technotes/App-Transport-Security-Technote/
我几天前完成了我的应用程序,并安装了 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.
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()
}
P.S。这些代码行在两个 ViewControllers 中大多相似,但错误是相同的
这是您在 Info.plist
中应该拥有的示例:
更多信息在这里:https://developer.apple.com/library/prerelease/ios/technotes/App-Transport-Security-Technote/