For iOS7, Apple supports several background operating modes, BACKGROUNDTASK,VOIP, background music, etc., depending on the official document is good.
I need to run a long-running timer in the background, so I can't get the app into the suspend state.
Heard long ago can be played by the background music to achieve, borrowed a bit, testing for several days, find out a more reliable solution:
First in
-(void) Applicationdidenterbackground: (uiapplication *) application{
}
Inside Application Backgroundtask
[[UIApplication sharedapplication] Beginbackgroundtaskwithexpirationhandler:nil]
Implement a permission that can run for several minutes.
Then write a timer real-time detection backgroundtimeremaining
-(void) tik{
if ([[UIApplication sharedapplication] backgroundtimeremaining] < 61.0) {
[[Ckaudiotool sharedinstance] playSound];
[[UIApplication sharedapplication] beginbackgroundtaskwithexpirationhandler:nil];
}
}
[[Ckaudiotool sharedinstance] playSound]; this piece of code is going to play a silent music, and the key point is
[[Avaudiosession sharedinstance] Setcategory:avaudiosessioncategoryplayback withoptions: Avaudiosessioncategoryoptionmixwithothers Error:&error]
This way, background playback will not affect other programs to play music.
I run this timer every minute Tik function, if the background run time is less than a minute, then go to apply for a backgroundtask.
The Magical place is: Backgroundtask can not be in the program has entered the background when the application, you may use a music playing the false foreground status to apply, so you can continue to apply to the authority, also completed a long time backstage execution.
application example "classmate Alarm clock". (This can be through the apple audit??? )
iOS play audio for long time background run (rogue)