我首先自己定义了AFImageRequestOperation,然后把他加到NSOperationQueue,我是用一个循环加的,加了大概500个左右,如下:
AFImageRequestOperation * _128RequestOperation = [[AFImageRequestOperation alloc] initWithRequest:[download fetchUrlRequest:[download fetch128ImageUrl:tmpWheel]]];
__weak AFImageRequestOperation * _128weakOperaion = _128RequestOperation;
[_128RequestOperation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
//NSLog(@"in _128 Operation ");
if ([_128weakOperaion isCancelled])
return;
[download downloadImgAndSave2Disk:responseObject withImgName:[NSString stringWithFormat:@"%@@2x",thumbName] withFileType:@"png"];
[self.statusToolbar updateProgressBar:1 withTotalValue:totalProgress];
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
;
}];
[self.downloadQueue addOperation:_128RequestOperation];
我在viewDidLoad中加入了,如下:NSNotificationCenter
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(appDidEnterBackgroundNotification)
name:UIApplicationDidEnterBackgroundNotification
object:nil];
然后appDidEnterBackgroundNotification如下:
NSLog(@"hello i am in appDidEnterBackgroundNotification ...");
[self.downloadQueue cancelAllOperations];
当我按我自己itouch的home键的时候,如果我启动了addOperation,则我的那句nslog日志打不出来。operation也停步了。
如果我没有启动过addOperation,则我可以打印nslog的那句日志。
并且非常奇怪的是,我在6.1模拟器中,不管怎么操作都是能停的。
请问是什么原因?急!谢谢
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。
是这样的,我原本在AFImageRequestOperation的setCompletionBlockWithSuccess做了很多其他的事情,我现在把这些事情,都封装成为一个NSOpeartion,然后加入到QUEUE中,这样,按Home键后,就能打印出log了