我幾天前完成了我的應用程序,並安裝了Xcode 7,這是一個痛苦的屁股,我有很多問題,但設法修復其中的大部分,但現在,當我的應用程序需要連接到互聯網,我得到這個奇怪的錯誤 這是我得到什麼記錄:應用程序運輸安全崩潰Swift 2.0應用程序
應用傳輸安全性已阻止明文HTTP(HTTP://)資源 負載,因爲它是不安全的。臨時例外可以通過 您的應用程序的Info.plist文件進行配置。 Hempel.temp_caseinsensitive_rename對 進行了優化編譯 - 步進可能表現異常;變量 可能不可用。
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大多相似,但錯誤是相同
我當然,如果你谷歌'應用程序運輸安全',並做一些閱讀,你會發現它。 –
http://stackoverflow.com/questions/30889312/api-call-error-in-xcode-7-ios-9-how-to-setup-app-transport-security-in-plist –
對不起,我很害怕當我看到錯誤時,請通過 –