hal*_*y4b 4 ios afnetworking-2
有没有办法取消AFHTTPRequestOperation?我用它来下载PLIST例如.所以我打算用一个按钮来取消下载或任务.有办法吗?
更新:
operationQueue = [NSOperationQueue new];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:myURL] cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:30.0];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
operation.responseSerializer = [AFPropertyListResponseSerializer serializer];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id propertyList) {
NSLog(@"DONE");
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"%@", error);
}
];
[operationQueue addOperation:operation];
Run Code Online (Sandbox Code Playgroud)
所以我把"操作"放到"operationQueue"并且可以用以下命令停止操作:
[operationQueue cancelAllOperations];
Run Code Online (Sandbox Code Playgroud)
这只是队列中的一个操作.如果有多个,有没有办法明确停止操作?我想在控制台中出现以下错误 - 如果队列被取消,这是正常的吗?
错误域= NSURLErrorDomain代码= -999"无法完成操作.
Aar*_*ger 12
您可以使用:
[operation cancel];
Run Code Online (Sandbox Code Playgroud)
这是一种由AFNetworking实施的NSOperation方法.
| 归档时间: |
|
| 查看次数: |
6147 次 |
| 最近记录: |