开发者

iPhone App: How do I call a function after my iPhone has been to sleep?

开发者 https://www.devze.com 2023-01-05 04:43 出处:网络
I have an app with some animations which are called by timers. When one animation finishes then a timer is called to start another. If the iPhone sleeps and requires unlocking to activate it then the

I have an app with some animations which are called by timers. When one animation finishes then a timer is called to start another. If the iPhone sleeps and requires unlocking to activate it then the animations do not start. This is obviously because the timer ends whilst 开发者_如何学编程the app is asleep and then the function to restart an animation doesn't get called.

What I want to do is check if the animations are running and if not activate them - or maybe stop them when the app sleeps and activate them when it starts again.

I have been trying to find a method to do this but after hours of googling I can't find anything - it is completely possible I'm not searching for the right thing!

Any suggestions would be greatly appreciated?

Also is there a way of forcing the iPhone to sleep when connected to XCode?

THANKS


When the iPhone screen locks the notification UIApplicationWillResignActiveNotification is sent. After the screen is unlocked the notification UIApplicationDidBecomeActiveNotification is sent. You have two choices:

  1. You can register with NSNotificationManager to get UIApplicationDidBecomeActiveNotification notification and restart your timers after wakeup if they are invalidated.

  2. You can implement applicationDidBecomeActive in your app delegate and restart your timers there if they are invalidated.

0

精彩评论

暂无评论...
验证码 换一张
取 消