내 타이머가 무작위로 작동하지 않는 문제가 발생했습니다. 말 그대로 앱을 중지하고 코드를 변경하지 않고 다시 빌드 할 수 있습니다. 때로는 효과가 있고 때때로 그렇지 않습니다. "때때로"나는 앱 세션 당 이야기하고 있습니다. 시작되면 실행 상태를 유지합니다. 그러나 모든 앱 세션을 실행하지는 않습니다. 아래의 두 코드 블록을 모두 사용하는 경우에도 동일한 결과가 나타납니다.NSTimer는 가끔씩 만 발생합니까?
//Code1:
//I tried this block of code after reading it might be related to how I am interacting with my UIElements while the timer is running in the background.
NSRunLoop *runloop = [NSRunLoop currentRunLoop];
syncWithServerTimer = [NSTimer timerWithTimeInterval:15 target:self selector:@selector(syncWithServer) userInfo:nil repeats:YES];
[runloop addTimer:syncWithServerTimer forMode:NSRunLoopCommonModes];
[runloop addTimer:syncWithServerTimer forMode:UITrackingRunLoopMode];
//Code2:
syncWithServerTimer = [[NSTimer scheduledTimerWithTimeInterval:15 target:self selector:@selector(syncWithServer) userInfo:nil repeats:YES] retain];
다시 말하지만, 나는이 두 가지를 시도하고 그들 모두는 모든 시간을 대부분의 시간을 작동하지만하지. 무엇이 문제 일 수 있습니까? 나는 조기에 석방하거나 무효화하지 않습니다.
타이머 초기화 (게시 한 코드)는 어떤 방법으로 실행합니까? – sergio
안녕하세요 @sergio의 in -viewDidLoad – Louie
더 많은 코드를 보지 않고도 말할 수 없습니다. 두 가지 모두 -viewDidLoad에 삽입하면 잘 작동하는 것처럼 보입니다. 다른 인스턴스를 시작하기 전에 Xcode에서 앱을 종료 한 후 제대로 기다리지 않았을 수 있습니까? –