Understanding allows positioning, audio, VoIP.

Source: Internet
Author: User

We all know that our program runs in the background for 10 minutes and stops after 10 minutes. But like real-time positioning, playing audio, and VoIP, we need to keep running in the background. Then we're going to set it up accordingly.

- (void) Applicationdidenterbackground: (UIApplication *) application{/*Use the method to release shared resources, save user data, invalidate timers, and store enough application stat         E information to the restore your application to the it is terminated later.  If your application supports background execution, this method is called instead of Applicationwillterminate:when the      User quits. */        if([[[Uidevice Currentdevice] Respondstoselector: @selector (ismultitaskingsupported)]) {//Check If our iOS version supports multitasking i.e iOS 4        if([[[Uidevice Currentdevice] ismultitaskingsupported]) {//Check If device supports mulitaskingUIApplication *application =[UIApplication sharedapplication]; //Get The shared application instance__block Uibackgroundtaskidentifier Background_task; //Create a Task objectBackground_task= [Application Beginbackgroundtaskwithexpirationhandler: ^{                  /*when the application is in the background of 0 o'clock, the following actions are performed (the application will stay in the background for 600s, which can be viewed by backgroundtimeremaining) */[Application Endbackgroundtask:background_task]; //Tell the system, we are doing with the tasksBackground_task =Uibackgroundtaskinvalid; //Set the task to be invalid//System would be shutting down the app at any point in time now            }]; //Background tasks require use asyncrous tasksDispatch_async (Dispatch_get_global_queue (Dispatch_queue_priority_default,0), ^{                  //Perform your tasks that your application requiresNSLog (@"Time remain:%f", application.backgroundtimeremaining);                 [Application Endbackgroundtask:background_task]; //The End of the task so the system knows that ' is done with the what's need to performBackground_task = Uibackgroundtaskinvalid;//Invalidate the Background_task            }); }      }    }

To modify the application's Info.plist file, you need to add the Uibackgroundmodes field to the Info.plist file, which is the value type of all background modes supported by the app. Currently this array can contain three string constants such as "audio", "Location", and "VoIP".

Understanding allows positioning, audio, VoIP.

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.