我想暂停后台任务。我带着计时器方法来这个天真的块。 它接缝在调试模式下工作,但是没有断点,计时器永远不会被触发?
下面是一些伪代码
- (void) processQueryWithCompletion:(void (^)( BOOL succeed, NSError *error, NSInteger nbItemProcessed )) completionHandler timeOut:(NSTimeInterval) maxDuration {
__block BOOL timerHasBeenFired=FALSE;
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:1 block:^{
timerHasBeenFired=TRUE;
completionHandler( FALSE, nil );
} repeats:FALSE];
[query findObjectsInBackgroundWithBlock: ^( NSArray *objects, NSError *error ) {
if (timerHasBeenFired) {
return ;
}
[timer invalidate];
//do stuff
completionHandler( FALSE, nil );
}];
}