5 초 동안 트리거 된 타이머가 글로벌 대기열에 추가되었지만 2 초 후에 무효화되지만 실행 루프는 5 초까지 종료되지 않습니다. 다음 스 니펫에서 backgroundTimer는 인스턴스 var이고 run은 멤버 함수입니다. 실행 루프 종료를 차단하는 다음 코드에서 무엇이 잘못 되었습니까?즉시 runloop에서 타이머를 제거하는 방법
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
_backgroundTimer = [NSTimer timerWithTimeInterval:5 target:self selector:@selector(run) userInfo:nil repeats:NO];
[ [NSRunLoop currentRunLoop] addTimer:_backgroundTimer forMode:NSRunLoopCommonModes];
[[NSRunLoop currentRunLoop] run];
NSLog(@"Run loop terminated");
});
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
[_backgroundTimer invalidate];
_backgroundTimer=nil;
});
심지어 CFRunLoopStop ([[NSRunLoop currentRunLoop] getCFRunLoop])을 추가하려고 시도했습니다. 무효화 후, – pradeepa