Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Play sound at specific time while app is in background

I'm looking for some way to let my app play a sound at a specific time while it's in the background (IOS4 multitasking). Currently, I use local notifications for that which works quite well, except for:

  • the sound will not be played if the phone is muted
  • the 30 second playback limit

I saw there's setKeepAliveTimeout:handler: but it's only available for voip-apps and since that's not the purpose of my app, I guess Apple would reject it because of this. I also saw a solution where an "empty" sound is being played until it's time has been reached, but - ignoring that this is not a very elegant way, anyways - I read that this, too, might get the app rejected.

Since there are a few alarm clock apps that do just what I'm looking for, I wonder how they implemented this functionality.

Thanks for any hints in advance!

like image 516
trautwein Avatar asked Apr 29 '11 22:04

trautwein


1 Answers

If you seek a solution that will be approved by Apple, you're right you can't use the setKeepAliveTimeout:handler and even if you could - you can't set the timeout to something that's smaller than 600 seconds, so I guess it won't be of a great use anyway (besides that It's not guaranteed to fire the event even remotely close to the timeout you specified. For example, I set it to 600 seconds and some event fired as early as 360 seconds..).

About playing the silent sound, except the waste of battery, if you're app has legitimate use for background audio (if you're implementing an alarm clock, that's pretty obvious), I don't see a reason for your app to be rejected, as long as you don't try to use other background features (GPS signal, VoIP handlers, etc).

Here's one example app that used this "feature" for their benefit: http://tapbots.com/blog/pastebot/pastebot-music-in-background

About other methods, you can look in this thread: How do I start playing audio when in silent mode & locked in iOS 6?

On a personal note, it's not very easy to cope with background policies of Apple. Me and my company had (have?) a hard time just to maintain a simple VoIP connection due to all the limitations. My best advice is try to do as less as possible in the background as you can. If the UILocalNotificaion solution suits you, you'll probably should stick to it and live with the limitations.

like image 135
Sagi Iltus Avatar answered Sep 27 '22 16:09

Sagi Iltus