views:

123

answers:

3

Hi,

I have a small application which is much like a clock. It has been working great on IOS3, but now I am updating it to iOS4. What I want to do in iOS4 is to let it play a sound any giving time. For instance, if I set it to play at 4.00 PM I want it to play a sound, a sound from the application not from the OS. This works if the app is launced, but if the user went back to the home screen I want the same to happen.

It is OK if a UIAlertView pops up istead of the application.

How can I do this?

Best regards, Paul Peelen

A: 

Read http://developer.apple.com/iphone/library/documentation/iphone/conceptual/iphoneosprogrammingguide/BackgroundExecution/BackgroundExecution.html.

What you want is UIApplication setKeepAliveTimeout:handler: which let you register a handler that will be called. You can use that to start playing audio. (Of course, compute the timeout when your app goes to background)

EDIT: Use UILocalNotification as andy said.

Nicolas Goy
According to the documentation setKeepAliveTimeout:handler is only for apps registered as VOIP apps.
andynormancx
A: 

Two things you could possibly try under iOS 4.

Local Notifications can pop up an alert and play a short sound.

Another power hungry option is to register as a background music player, and play silence until time for the alarm to go off, then add your chosen sound to the "music" output. This will fail if the user switches to another media player app.

hotpaw2
Local Notifications will cause the OS to play the sound, not the app, which isn't exactly what the OP requested. Thus the 2nd non-optimal solution to exactly the question as asked: how to let the application play a sound.
hotpaw2
Apparently Apple don't like the long-intervals-of-silence thing. Tapbots got knocked back trying to do something similar with Pastebot. They got around it by adding a mini mediaplayer to the app. The OP's request refers to a "sound from the application not from the OS" - UILocalNotification can play a sound from the app's main bundle as part of the notification, does this meet the objective?If the requirement is for the app to generate a sound and play that - you may be out of luck as an app's main bundle is AFAIK not writable by the app.
Alan Rowarth