我試圖超時我的NSOperation
與NSTimer
但我的計時器沒有被解僱。請參閱下面的代碼我寫在我的班級裏面,這是NSOperation
。無法使用NSTimer超時NSOperation
- (void)start {
// Start the timer for Time out before the ping activity starts
self.timeOutTriggerTimmer = [NSTimer scheduledTimerWithTimeInterval:10.0 target:self selector:@selector(cancelTheOperation) userInfo:nil repeats:NO];
[[NSRunLoop currentRunLoop] addTimer:self.timeOutTriggerTimmer forMode:NSDefaultRunLoopMode];
// Check for cancellation
if ([self isCancelled]) {
[self completeOperation];
return;
}
// Executing
[self willChangeValueForKey:@"isExecuting"];
executing = YES;
[self didChangeValueForKey:@"isExecuting"];
// Begin
[self beginOperation];
}
接受這個答案,因爲它更有意義。謝謝@Rob。 – Abhinav