NSURLSession delegate vs. completionHandler
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I've always used completion handlers. With NSURLConnection and now with NSURLSession . It's led to my code being really untidy, especially I have request within request within request. I wanted to try using delegates in NSURLSession to implement something I've done untidily with NSURLConnection . So I created a NSURLSession , and created a dataTask : NSURLSessionDataTask *dataTask = [overallSession dataTaskWithURL:url completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { if(error == nil) { NSString * text = [[NSString