I am trying to let my program playing a recurring sound in background.
-
add (Required Background Modes) property and (apps play audio) in info.plist.
-
In my storyboard, app starts a UINarvigation controller with a root TableViewController. have #import in my Root TableViewController.m.
-
There is a NSTimer property, my_timer, in my Root TableViewController. I set it in viewDidLoad method as following:
my_timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector: @selector(doMyFunction) userInfo:nil repeats:YES];
- In doMyFunction method, I have playSystemSound(1003).
My app plays sounds periodically as expected when in front mode, but never gets played in back ground mode. I can’t figure out what is done not correctly, thank for your help.
playSystemSound will never play audio in background. To do that call this function in your main source code, just afer ViewDidLoad:
Then