Source Address: http://fann.im/blog/2014/02/25/ios-7-background-fetch/
IOS 7 adds three new background task APIs: Background Fetch background acquisition, Silent Remote Notifications silent Push, ?Background Transfer Service background transfer.
Background Fetch is dispatched by the system, and the application can make certain network requests in the background. The limitation here is that the background operation only allows 30s, and the time-out of the unfinished application will be killed directly, so it is only suitable for simple network requests.
The Silent Remote notifications can be controlled by the server, and the app can do some operations based on the message content (Content-id) via the message background, but also the 30s limit.
Background Transfer Services can be in the background for large network file download, upload operation, there is no time limit, but only under Wi-Fi, and by the system scheduling may be intermittent. Generally can be used together with the silent push, such as TV series update, silent push the latest episode of information to the mobile phone, the application background new download task and then gradually download, download completed after the Local notifications notify the user to watch.
Background Fetch Use steps:
1 in Target - Capabilities open Background Modes , tick Background Fetch . You can also manually modify Info.plist additions UIBackgroundModes - fetch .
2 Set background get time interval:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ [application setMinimumBackgroundFetchInterval:UIApplicationBackgroundFetchIntervalMinimum]; return YES;}
3 Perform a background fetch and notify the system after completion:
-(void)Application:(UIApplication*)ApplicationPerformfetchwithcompletionhandler:(void(^)(Uibackgroundfetchresult))Completionhandler{//...[FetcherFetchdatawithresult:^(Nserror*Error,NSData*Data){if (error) { Completionhandler (uibackgroundfetchresultfailed} else {//Parse data if (hasnewdata) {completionhandler (uibackgroundfetchresultnewdata} else {completionhandler (uibackgroundfetchresultnodata); } } }]; /span>
Note that it is important to call after the request is complete completionHandler(); , or the request may be interrupted by the system. You can work with Nsoperation + KVO after all operations have been completed completionHandler(); .
Xcode 5 provides two ways to test Background Fetch, one is to simulate when the emulator runs, through the Xcode menu, and Debug - Simulate Background Fetch to modify the application Scheme to select and Launch due to a background fetch event run the app, when the app doesn't open the interface and actually runs in the background.
Refer to multitasking in iOS 7, WWDC session notes-multitasking in IOS7, iOS 7:background Fetch.
iOS 8: "Go" ios 7 Background Fetch