在我的第一个屏幕上,我想加载并缓存几个JSON调用和图像调用。如果用户在完成之前单击第二个视图控制器, 这些电话会被取消还是会完成?
AFNetworking中的示例调用:
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
manager.responseSerializer = [AFJSONResponseSerializer serializer];
manager.requestSerializer = [AFJSONRequestSerializer serializer];
NSString *arcURL = [NSString stringWithFormat:@"%@/arc/v1/api/locations/%i/mobile_home",MYHost(), locationID];
[manager GET:arcURL parameters:nil success:^(NSURLSessionDataTask *operation, id responseObject) {
// on return will get written to a cache
SDWebImage中的示例调用
NSURL *imageURL=[[NSURL alloc] initWithString:[mi objectForKey:@"instore_image_url"]];
SDWebImageManager *manager = [SDWebImageManager sharedManager];
[manager downloadWithURL:imageURL
options:0
progress:^(NSInteger receivedSize, NSInteger expectedSize)
{
// progression tracking code
}
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished)
{
if (image)
{
// image downloaded - just writing to cache
}
}];
}
答案 0 :(得分:3)
GET
,POST
等AFHTTPSessionManager
返回NSURLSessionTask
引用的方法。如果您离开发起请求的控制器,则请求将继续,除非您(a)保存对该NSURLSessionTask
对象的引用; (b)明确调用该对象的cancel
方法。
SDWebImage方法downloadWithURL
同样返回一个引用(在本例中是一个符合SDWebImageOperation
协议的对象),如果需要,可以cancel
。