简体   繁体   中英

NSTimer to fire while device is locked

I'm currently creating an alarm. I use NSTimer to schedule my alarms. My problem is when the device was put into locked mode my NSTimer doesn't fire. I think that the NSTimer will not fire because my app goes to suspended state when it is lock. Can you help me find a solution to my problem?

I've found some topics about UIBackgroundModes, but I don't know how it will help me.

Thanks..

The problem in UILocalNotification is when the device was in silent, the sound will not be hear. My implementation was I'm using NSTimer to fire an alarm when the app is in foreground or device is locked but app currently running. When the applicationDidEnterBackground: is called I schedule the UILocalNotification as the alarm.

You will have to use a local notification (UILocalNotification) for this to work.

Check out Apple's documentation for further details.

You can use Local Notifications for this purpose,even if your app is running in the background you can receive alerts via Local Notifications.

You can refer the below link for further details

http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Introduction/Introduction.html

Cheers

There is a little trick to keep the device awake, even if the user locks the screen.

The downside is, that it costs quite a lot of battery life. I've written a blog post on how to do this a while ago. How-To: Prevent iPhone from Deep Sleeping - blog.marcopeluso.com

This technique works on all iOS devices up to iOS 4.2.1 and I've got an approved alarm clock app on the App Store that uses this.

I have created a piece of drop-in code you can use. MMPDeepSleepPreventer on GitHub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM