首页 > 在使用了Operation的时候,NSNotificationCenter收不到消息

在使用了Operation的时候,NSNotificationCenter收不到消息

我首先自己定义了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了

【热门文章】
【热门文章】