views:

382

answers:

3

Hi friends,

I am developing an alarm clock application in iphone. I am not able to find how to set alarm which will trigger even if the app is not running. Please suggest me some code or tutorial to do it.

Thanks in advance.

+1  A: 

Push notifications... OR....

The other day I noticed that if I turned off the screen (with the button on the top) that my app was still getting gps updates....

So, I'm starting to think that just hitting the top button doesn't actually exit your app... You'd need to do some experiments to prove this... but maybe you could still play a sound with the screen off?

dicroce
Don't forget push notifications won't work if you're out of cell or wifi coverage.
progrmr
If you lock turn the screen off, after about 10 seconds, it goes into deep sleep mode. There is a class going round that stops this by playing a silent sound clip every 5 seconds.
Dyldo42
A: 

Local notifications!

(This is now the correct answer since iOS 4.0 so gimme the credits!! (jk))

Jonny
This may be the best solution at the moment, but it is by no means a good one. You can't call any code until the user presses a button, so all you can really do is play a short sound and display a message, which is nowhere near apt for an alarm app.
Dyldo42
Playing a sound is not enough for an alarm app? Humm, Apple's alarm app works this way, most alarm apps work that way. But yeah, you can't have your app booted automatically of course.
Jonny
A: 

There really is no good, clean solution at the moment. The best that I've been able to find is a class (http://code.google.com/p/iphone-insomnia/) that stops it from sleeping. With this running, you can do whatever you want, but it will most likely drain the battery quite fast.

One other half solution is that the iphone doesn't sleep if it is charging. So you could simply alert your users that the alarm will only work if the iPhone is charging before it is set and that they cannot leave the app.

Dyldo42