In my application i am running a timer in background for every 8 seconds to play a custom sound,it works fine ,but it get stops at later sometime,so how can i play the sound continuously in background?
Currently i am using the below code to play the sound in background
SystemSoundID soundID;
AudioServicesCreateSystemSoundID((__bridge CFURLRef)filePath, &soundID);
AudioServicesPlaySystemSound(soundID);
let me know the good solution to play the sound continuously in background
Short answer: your app is simply suspended.
Long answer: You are missing key parts of the background savvy implementation.
- You need to tell the iOS that you are an Audio App, and that you are requesting extra cycles when suspended.
- The
UIBackgroundModes
is subject to approval
From the documentation:
Background modes for apps:
UIBackgroundModes
value = audio
The app plays audible content to the user or records audio while in the background. (This content includes streaming audio or video content using AirPlay.)
If your app does not fall into any of the categories below, then your only option to extend backgrounding beyond the typical 5 seconds is to invoke -beginBackgroundTaskWithName:expirationHandler:
. You will likely be suspend within 30 seconds or so.
- audio
- location
- voip
- newsstand-content
- external-accessory
- bluetooth-central & bluetooth-peripheral
- fetch
- remote-notification