2
votes

I have just noticed that my timer callback function stops firing when iPhone screen gets locked. Is there anyway to tell iPhone to keep awake my timer? Any other way to do things periodically when iPhone is locked?

I am using NSTimer from viewDidLoad to schedule timer call back function every second.

[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector: @selector(levelTimerCallback) userInfo:nil repeats:YES];

Thanks.

1
@Radek S you're wrong. It can be levelTimerCallbackMax
@Max Documentation. It says: "The message to send to target when the timer fires. The selector must have the following signature: - (void)timerFireMethod:(NSTimer*)theTimer"user142019
@Radek S It should, if you want to get the caller (timer). But if there is no parameter, it is just skipped. If you don't believe - just test it. It works fineMax
I'll second the works fine thing. I tried it as well.DavidN
@Radek S you're confusing the SDK and the foundations of programming language. Messaging is the basis of Objective C (and it is absolutely independent from Cocoa), and it's almost certain that it's rules would not be changed in future.Max

1 Answers

1
votes

You sure it's not running when locked? I just tried it, put that scheduleTimerWithTimeInterval in the app delegate's didFinishLaunching method, locked screen on simulator, and still get the callbacks.