ASINetworkQueue使用cancelAllOperations方法来取消下载时使用的注意点 在 ASIHTTPRequest V1.7前提下 正确使用: imgDataDownLo
2014-04-08 17:02
459 查看
ASINetworkQueue使用cancelAllOperations方法来取消下载时使用的注意点
在 ASIHTTPRequest V1.7前提下正确使用:
imgDataDownLoadQueue = [[ASINetworkQueue alloc] init];
[imgDataDownLoadQueue setShouldCancelAllRequestsOnFailure:NO];
[imgDataDownLoadQueue setDelegate:self];
[imgDataDownLoadQueue setRequestDidFailSelector:@selector(imgDataRequestFail:)];
[imgDataDownLoadQueue setRequestDidFinishSelector:@selector(imgDataRequestFinish:)];
[imgDataDownLoadQueue setQueueDidFinishSelector:@selector(imgDataQueueDidFinish:)];
for(int i=0; i<[imgDatasToLoadArray count]; i++)
{
ASIHTTPRequest* imgRq = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:[[imgDatasToLoadArray objectAtIndex:i] objectForKey:@"imgurl"]]];
NSString* value[2];
NSString* key[2];
value[0] = [[imgDatasToLoadArray objectAtIndex:i] objectForKey:@"imgtime"];
value[1] = [[imgDatasToLoadArray objectAtIndex:i] objectForKey:@"index"];
key[0] = @"imgtime";
key[1] = @"index";
imgRq.userInfo = [NSDictionary dictionaryWithObjects:value forKeys:key count:2];
[imgDataDownLoadQueue addOperation:imgRq];
}
[imgDataDownLoadQueue go];
=======
这样在dealloc中取消下载
[imgDataDownLoadQueue setDelegate:nil];
[imgDataDownLoadQueue cancelAllOperations];
[imgDataDownLoadQueue release];
imgDataDownLoadQueue = nil;
不会导致crash.
#######################################################3
如果按这种方法使用:
imgDataDownLoadQueue = [[ASINetworkQueue alloc] init];
[imgDataDownLoadQueue setShouldCancelAllRequestsOnFailure:NO];
[imgDataDownLoadQueue setDelegate:self];
for(int i=0; i<[imgDatasToLoadArray count]; i++)
{
ASIHTTPRequest* imgRq = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:[[imgDatasToLoadArray objectAtIndex:i] objectForKey:@"imgurl"]]];
NSString* value[2];
NSString* key[2];
value[0] = [[imgDatasToLoadArray objectAtIndex:i] objectForKey:@"imgtime"];
value[1] = [[imgDatasToLoadArray objectAtIndex:i] objectForKey:@"index"];
key[0] = @"imgtime";
key[1] = @"index";
imgRq.userInfo = [NSDictionary dictionaryWithObjects:value forKeys:key count:2];
[imgRq setRequestDidFailSelector:@selector(imgDataRequestFail:)];
[imgRq setRequestDidFinishSelector:@selector(imgDataRequestFinish:)];
[imgDataDownLoadQueue addOperation:imgRq];
}
[imgDataDownLoadQueue go];
在dealloc中
[imgDataDownLoadQueue setDelegate:nil];
[imgDataDownLoadQueue cancelAllOperations];
[imgDataDownLoadQueue release];
imgDataDownLoadQueue = nil;
将会导致ASIHttpRequist的Crash.
相关文章推荐
- ASINetworkQueue使用cancelAllOperations方法来取消下载时使用的注意点
- ASINetworkQueue使用cancelAllOperations方法来取消下载时使用的注意点
- ASINetworkQueue使用cancelAllOperations方法来取消下载时使用的注意点
- 如何使用ASINetWorkQueue下载实现
- ASIHTTPRequest和ASINetworkQueue实现队列下载并查看结果
- ASIHTTPRequest和ASINetworkQueue实现队列下载
- ASINetworkQueue 队列下载
- ASINetworkQueue 队列下载
- Data Access Application Block(Enterprise Library 3.1)的下载以及使用方法介绍
- jQuery $.data()方法使用注意细节
- ASIHTTPRequest和ASINetworkQueue实现队列下载并查看结果
- jQuery $.data()方法使用注意细节
- iOS_使用NSURLSessionDataDelegate的代理方法下载数据
- jQuery $.data()方法使用注意细节
- iOS_使用NSURLSessionDataDelegate的代理方法下载数据
- Query $.data()方法使用注意细节
- jquery load事件(callback/data)使用方法及注意事项
- 在子线程中使用runloop,正确操作NSTimer计时的注意点 三种可选方法
- 【iOS开发每日小笔记(九)】在子线程中使用runloop,正确操作NSTimer计时的注意点 三种可选方法
- 使用Docker Toolbox 创建v1.12.6版的Docker虚拟机的方法-注意正确使用本地文件 file:参数的路径名