0
計時器定更新一些計數器:的NSTimer不點火
-(void)_tock:(NSTimer *)aTimer {
NSLog(@"%p %p tock from %p", self, [NSThread currentThread], aTimer);
...
}
它從主線程設置並添加到runloop自動(使用時間表而不是timerWith):
-(void)setRotationsPerMinute:(float)rotationsPerMinute
{
// force calling from the main thread - as per hint on the invalidate method.
[self performSelectorOnMainThread:@selector(setRotationsPerMinuteObj:)
withObject:[NSNumber numberWithFloat:rotationsPerMinute]
waitUntilDone:NO];
}
-(void)setRotationsPerMinuteObj:(NSNumber *)rotationsPerMinuteAsObj
{
_rotationsPerMinute = [rotationsPerMinuteAsObj floatValue];
[self.rotationUpdateTimer invalidate]; // <----- invalide timer
self.rotationUpdateTimer = nil; // <----- wipe
....
// <--- replace timer
self.rotationUpdateTimer = [NSTimer scheduledTimerWithTimeInterval:interval
target:self
selector:@selector(_tock:)
userInfo:nil
repeats:YES];**
NSLog(@"%p %p New timer is %p - will fire in %f seconds", self,
[NSThread currentThread], self.rotationUpdateTimer, interval);
[self setNeedsDisplay];
}
這項工作最初花錢多。但是,當我將它作爲遠程推送通知的結果進行更改時 - 不知何故,它不再觸發。
調試輸出顯示滴答射擊很好:
2013-07-29 14:46:21.999 XXX[589:707] 0x1523b0 0x11a5e0 tock from 0x178890
2013-07-29 14:46:22.014 XXX[589:707] 0x1523b0 0x11a5e0 tock from 0x178890
2013-07-29 14:46:22.029 XXX[589:707] 0x1523b0 0x11a5e0 tock from 0x178890
2013-07-29 14:46:22.044 XXX[589:707] 0x1523b0 0x11a5e0 tock from 0x178890
2013-07-29 14:46:22.063 XXX[589:707] 0x1523b0 0x11a5e0 tock from 0x178890
然後我們得到推在未來 - 這確實一個setRotationsPerMinute:XX呼叫。
2013-07-29 14:46:22.074 XXX[589:707] Push received: {
aps = {
alert = XXX;
badge = 1;
sound = default;
};
}
由於setRotationsPerMinute的結果是:撥打我們看到了變化:
2013-07-29 14:46:22.081 XXX[589:707] Makers 1 - active 1 -- 16.000000
,然後創建新的計時器:
2013-07-29 14:46:22.089 XXXX[589:707] 0x1523b0 0x11a5e0 New timer is 0x15dbc0 - will fire in 0.060000 seconds
但是 - 它不會從火在其上。任何建議 - 有一種感覺,我失去了一些非常明顯的東西!
謝謝!
你在創建新定時器的線程是什麼? –
我*認爲*我正在使用performSelectorOnMainThread:強制它始終在主線程 - 即setRotationsPerMinute:v.s.中的調用。 setRotationsPerMinuteObj: –