2015-09-24 132 views
1

我几天前完成了我的应用程序,并安装了Xcode 7,这是一个痛苦的屁股,我有很多问题,但设法修复其中的大部分,但现在,当我的应用程序需要连接到互联网,我得到这个奇怪的错误 这是我得到什么记录:应用程序运输安全崩溃Swift 2.0应用程序

应用传输安全性已阻止明文HTTP(HTTP://)资源 负载,因为它是不安全的。临时例外可以通过 您的应用程序的Info.plist文件进行配置。 Hempel.temp_caseinsensitive_rename对 进行了优化编译 - 步进可能表现异常;变量 可能不可用。

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大多相似,但错误是相同

+2

我当然,如果你谷歌'应用程序运输安全',并做一些阅读,你会发现它。 –

+3

http://stackoverflow.com/questions/30889312/api-call-error-in-xcode-7-ios-9-how-to-setup-app-transport-security-in-plist –

+0

对不起,我很害怕当我看到错误时,请通过 –

回答

2

下面是你应该在Info.plist什么一个例子:

screen

此处了解详情:https://developer.apple.com/library/prerelease/ios/technotes/App-Transport-Security-Technote/

+1

来了解一个重要的区别IMO:如果您接受通过HTTP加载不安全内容的责任,而不是HTTPS_,那么您应该在Info.plist中拥有这些内容。您**应该**实际上做的是,如果它在您的控制范围内,则是通过HTTPS加载您的内容。 –

+0

@CraigOtis谢谢,这是一个有价值的笔记! – rshev