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

发布于 2022-08-25 01:38:51 字数 1929 浏览 13 评论 0

我首先自己定义了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模拟器中,不管怎么操作都是能停的。
请问是什么原因?急!谢谢

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

下壹個目標 2022-09-01 01:38:51

是这样的,我原本在AFImageRequestOperation的setCompletionBlockWithSuccess做了很多其他的事情,我现在把这些事情,都封装成为一个NSOpeartion,然后加入到QUEUE中,这样,按Home键后,就能打印出log了

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文