Unlimited task execution in IOS background

Source: Internet
Author: User

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:

 

  1. _ Block UIBackgroundTaskIdentifier background_task;
  2. Background_task = [application beginBackgroundTaskWithExpirationHandler: ^ {[application endBackgroundTask: background_task];
  3. Background_task = UIBackgroundTaskInvalid;}];
  4. Dispatch_async (dispatch_get_global_queue (DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^ {
  5. While (TRUE ){
  6. [NSThread sleepForTimeInterval: 1];
  7. // Write the execution task code
  8. }
  9. [Application endBackgroundTask: background_task]; background_task = UIBackgroundTaskInvalid;
  10. });

     

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.