0

I have a navi-like app, that plays notifications dependant on some location and time based actions.

The problem is that the notification sound must be combined from 2 or more files.

Normally it wouldn't be a problem since I'd combine audio and play it like it was suggested here.

Problems start when the app is moved to background. I was planing to use UILocalNotification in this case. Unfortunatelly, UILocalNotification only lets me to set soundName property as a name of file. Since the sound is combined out of couple of files, I can't provide such audio file name right?

What is the correct approach here? Can I use combined audio while app is in background?

Community
  • 1
  • 1
Jacek Kwiecień
  • 12,397
  • 20
  • 85
  • 157

1 Answers1

1

No not with UILocalNotification since the soundName has to be in de main bundle. Also the sound may not play longer then 30 seconds.

You might be able to register your app for background audio player, but you will have to be playing a file or at least have the audio service know that you will be playing a sound before your app is pushed to the background to keep it alive.

Have a look at AVFoundation and Playing media while in the background using AV Foundation on iOS

rckoenes
  • 69,092
  • 8
  • 134
  • 166
  • How the navigation apps do this? Are they using Siri or something? – Jacek Kwiecień Jan 07 '14 at 12:28
  • No they open a register for background running use location and sound, then start the sound service for background audio. – rckoenes Jan 07 '14 at 12:30
  • I could do that, but can I schedule start of audio on desired time, like I would do it with localNotification? Maybe there is some code, that localnotification executes? Unfortunatelly didReceiveLocalNotification is executed nly after the app is opened from notification. – Jacek Kwiecień Jan 07 '14 at 12:36
  • `UILocalNotification` are only directly handled by your app if it is in the foreground. Other they are just handled by iOS. So unless your app is actively running in the background you can't really schedule any thing. Just use AVFoundation and set you audiosession to [`AVAudioSessionCategoryAmbient`](https://developer.apple.com/library/ios/documentation/Audio/Conceptual/AudioSessionProgrammingGuide/AudioSessionCategories/AudioSessionCategories.html) – rckoenes Jan 07 '14 at 12:40
  • It seems I can't use NSTimer and UILocalNotification for scheduling AUdioSession since the app can be in background. The only place for checking it might be didUpdateLocations since my location is refreshed every few seconds in the background? It's not too precise though... – Jacek Kwiecień Jan 07 '14 at 12:54
  • 1
    WHoa, thats not exactly true, NSTimer keeps working while backround modes enabled! – Jacek Kwiecień Jan 08 '14 at 09:57