我必须在代码中更改以解决此警告?警告如下:
在iOS 9中不推荐使用sendAsynchronousRequest,使用dataTaskWithRequest:completionHandler
这是我的代码:
func collectionVIEw(collectionVIEw: UICollectionVIEw,cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionVIEwCell { // try to reuse cell let cell = collectionVIEw.dequeueReusableCellWithReuseIDentifIEr(reuseIDentifIEr,forIndexPath: indexPath) as! marcaCollectionVIEwCell // get the deal image let currentimage = marcas[indexPath.row].imagen let unwrappedImage = currentimage var image = self.imageCache[unwrappedImage] let imageUrl = NSURL(string: marcas[indexPath.row].imagen) // reset reused cell image to placeholder cell.marcaimageVIEw.image = UIImage(named: "") // async image if image == nil { let request: NSURLRequest = NSURLRequest(URL: imageUrl!) NSURLConnection.sendAsynchronousRequest(request,queue: NSOperationQueue.mainQueue(),completionHandler: {(response: NSURLResponse?,data: NSData?,error: NSError?) -> VoID in if error == nil { image = UIImage(data: data!) self.imageCache[unwrappedImage] = image dispatch_async(dispatch_get_main_queue(),{ cell.marcaimageVIEw.image = image }) } else { } }) } else { cell.marcaimageVIEw.image = image } return cell}解决方法 警告警告,NSURLConnection已经死亡. NSURLSession万岁.
let session = NSURLSession.sharedSession()let urlString = "https://API.yoursecureAPIservergoeshere.com/1/whatever"let url = NSURL(string: urlString)let request = NSURLRequest(URL: url!)let dataTask = session.dataTaskWithRequest(request) { (data:NSData?,response:NSURLResponse?,error:NSError?) -> VoID in print("done,error: \(error)")}dataTask.resume()总结
以上是内存溢出为你收集整理的在iOS 9中不推荐使用sendAsynchronousRequest全部内容,希望文章能够帮你解决在iOS 9中不推荐使用sendAsynchronousRequest所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)