IOS7 Background Fetch Background Application refresh

Source: Internet
Author: User

In the previous article <ios background operation analysis > briefly explained in the iOS platform to perform background tasks need to pay attention to the problem, today cool bar mainly say IOS7 New added background features background Fetch. Background fetch key users need to regularly update the data of the app, such as timely communications, microblogging and other apps. IOS7 users can switch this feature on in Settings, general-purpose, background application refresh.
For more information on background fetch please refer to: <ios 74 background mechanism > For background fetch explanation, here is just how to use background fetch.
Oneturn on background fetch support
Open and add Background Fetch in Xcode->targets->capabilities->background modes.
Simultaneous in-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) The Launchoptions method adds:
[[UIApplication Sharedapplication] Setminimumbackgroundfetchinterval:uiapplicationbackgroundfetchintervalminimum ];
The Minimumbackgroundfetchinterval parameter value is two fetch interval and cannot be guaranteed to be called every time interval. This is set to Uiapplicationbackgroundfetchintervalminimum, which means calling our fetch method as frequently as possible.
Twoincreased implementation of fetch methods
-(void) Application: (UIApplication *) application Performfetchwithcompletionhandler: (void (^) ( uibackgroundfetchresult)) completionhandler{};
This method is called every time the system fetch, we can do the refresh data in the method, and then call Completionhandlerblock () after the operation completes, for example: Completionhandler ( Uibackgroundfetchresultnewdata), the document says the system will estimate the power consumption of the fetch according to the Completionhandler (time of execution). If the time consuming consumes more, it may decrease the number of times it is called. However, this method is not a time-limited execution, saying that there is a 30s to perform the operation. The Completionhandler has three parameters:
Uibackgroundfetchresultnewdata successfully pulled data
Uibackgroundfetchresultnodata no new data
Uibackgroundfetchresultfailed Pull data failed or timed out
ThreeSimulate Fetch events
In the actual IOS7 environment, the fetch event is managed by the system, and the app developer cannot know in advance what time the Fetch event was reached. But Xcode also provides a debugging method for the fetch event, after running the program on Xcode, Debug->simulate Background Fetch.
Another scenario is that the app is not running (not in the foreground or in the background) and is executed by the fetch event. The test method for this scenario is as follows:
Product->scheme->edit Scheme in debug mode select options, click Launch due to a background fetch event, run.
[Cool bar] can observe when the fetch event arrives, the app first enters the backstage, then executes-(void) Application: (UIApplication *) application Performfetchwithcompletionhandler: (void (^) (Uibackgroundfetchresult)) completionhandler{}.
Fourdetermine if the device has background application refresh enabled

FoldingC + + Codecopy content to clipboard
  1. if ([[UIApplication sharedapplication] backgroundrefreshstatus]! = uibackgroundrefreshstatusavailable)
  2. {
  3. Uialertview *alertview = [[Uialertview alloc] Initwithtitle:nil message:@"You have not turned on background refresh, please turn it on in the application background refresh, general-purpose, settings." delegate:nil cancelbuttontitle:@"OK" Otherbuttontitles:nil];
  4. [Alertview show];
  5. [Alertview release];
  6. }


Reprint please indicate from Cool bar, this article address: http://www.tekuba.net/program/320/
Reference reading:
iOS 74 background mechanism
iOS screen rotation control detailed iOS local and remote push notifications in detail
Communicating with and other app communication iOS app launch process lifecycle detailed

IOS7 Background Fetch background Application refresh

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.