Unlimited task execution in IOS background
Find some code for continuing to execute tasks in the ios background, and share it with you:
First, configure the Info-Plist file and create a new Required background modes in it. This is an array. Add the following content below:
App provides Voice over IP services (VOIP)
App plays audio or streams audio/video using AirPlay (audio)
App processes Newsstand Kit downloads (newsstand-content)
App communicates using CoreBluetooth (bluetooth-central
)
App shares data using CoreBluetooth (bluetooth-peripheral
)
App registers for location updates (location)
After adding, add the following code in-(void) applicationDidEnterBackground :( UIApplication *) application:
- _ Block UIBackgroundTaskIdentifier background_task;
- Background_task = [application beginBackgroundTaskWithExpirationHandler: ^ {[application endBackgroundTask: background_task];
- Background_task = UIBackgroundTaskInvalid;}];
- Dispatch_async (dispatch_get_global_queue (DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^ {
- While (TRUE ){
- [NSThread sleepForTimeInterval: 1];
- // Write the execution task code
- }
- [Application endBackgroundTask: background_task]; background_task = UIBackgroundTaskInvalid;
- });