Everything was OK, until yesterday when my app started to behave weirdly. It works OK on simulator but on iPhone4 it performs one additional cycle even after stopping it. Here's my initializer that creates a new CADisplayLink timer or resumes existing one:
-(void)initializeTimer{
if (self.theTimer == nil) {
self.theTimer = [CADisplayLink displayLinkWithTarget:self selector:@selector(gameLoop)];
self.theTimer.frameInterval = 2;
[self.theTimer addToRunLoop: [NSRunLoop currentRunLoop] forMode: NSDefaultRunLoopMode];
} else {
self.theTimer.paused = NO;
}
}
I need to stop and resume the timer quite frequently, so I'm stopping the timer with pause property:
self.theTimer.paused = YES;
Then I'm calling i开发者_JS百科nitializer that resumes it (self.theTimer.pause = NO). As said, it performs one additional call to selector method. Very strange, I had this app working with no CADisplayLink problems more than a month. I didn't do any updates to iPhone recently. In addition, systems sounds stopped to play at the same moment but AVAudioPlayer objects still work. As I said both timer and sounds works perfectly on simulator but I want to find out what causes a problem on iPhone. All stuff is done with pure UIKit. Any ideas where to start?
Very weird. I just removed my app from test iPhone 4, compiled and ran again on it, and the problem disappeared. I know that I didn't spotted the problem but after a lot of trial time I gave up. However, after that, I have submitted my app to the app store and it was approved. Hope that was some kind of debugging issue instead of being a real problem.
精彩评论