0

计划一个计时器来更新一些计数器:

-(void)_tock:(NSTimer *)aTimer {
    NSLog(@"%p %p tock from %p", self, [NSThread currentThread], aTimer);
    ...
}

它从主线程设置并自动添加到运行循环(使用调度而不是 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

但是 - 它不会从那里开火。任何建议 - 感觉我错过了一些非常明显的东西!

谢谢 !

4

1 回答 1

0

这个问题在 Xcode 6.1 附带的 SDK 中完全消失了。

于 2015-03-22T17:30:39.457 回答