The maximum length of time to run, not to challenge the limit, how long it takes to keep the test.
Note: Test with a real machine
Directly on the code
In the Appdelegate. m, add some code actions when you enter the background
- /**
- * Called when the app enters the background
- */
- -(void) Applicationdidenterbackground: (uiapplication *) application
- {
- /**
- * Status of App
- * 1. Death Status: No app opened
- * 2. Foreground operation status
- * 3. Background suspend state: Stop all animations, timers, multimedia, networking operations, it is difficult to do other operations
- * 4. Background running status
- */
- //to the operating system to apply for background running qualification, how long can be maintained, is uncertain
- Self.task = [Application beginbackgroundtaskwithexpirationhandler:^{
- When the background run time for the application has ended (expired), the block is called
- //
- Finish the mission.
- [Application EndBackgroundTask:self.task];
- // }];
- __block uibackgroundtaskidentifier task = [Application beginbackgroundtaskwithexpirationhandler:^{
- //When the background run time of the application has ended (expired), the block will be called
- //Hurry to finish the task
- [Application Endbackgroundtask:task];
- }];
- /**
- 1. Defining Variables Uibackgroundtaskidentifier Task
- 2. Execute the code on the right
- [Application beginbackgroundtaskwithexpirationhandler:^{
- When the background run time for the application has ended (expired), the block is called
- Finish the mission.
- [Application Endbackgroundtask:task];
- }];
- 3. Assign the return value of the right method to a task
- */
- //Set background mode in INFO.PLST: Required background modes = = APP plays audio or streams audio/video using AirPlay
- //engage in a 0kb MP3 file with no sound
- //Loop playback
- //Previous background mode has only 3 kinds
- //Maintain network connectivity
- //Multimedia Applications
- //VOIP: Internet telephony
- }
iOS development easy to implement background tasks (such as background play music, timers, background positioning, etc.)