Reputation: 7637
Will the UIApplicationDelegate
call performFetchWithCompletionHandler
if device is not connected to the internet ? The documentation isn't clear in this case.
Upvotes: 1
Views: 326
Reputation: 7637
After some tests I can claim that performFetchWithCompletionHandler
delegate method is not called if device is not connected to the internet.
Tested on iOS8 and iOS9.
Upvotes: 1
Reputation: 42598
-application:performFetchWithCompletionHandler:
isn't called when a download has completed. It's called by the system to give your app a chance to download data. You do normal error handling as you see fit.
-(void)application:(UIApplication *)application performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
NSURL *URL = // Your URL
[[[NSURLSession sharedSession] dataTaskWithURL:URL completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
if (error != nil) {
// Handle Error
completionHandler(UIBackgroundFetchResultFailed);
return;
}
// Process the data
completionHandler(UIBackgroundFetchResultNewData);
}] resume];
}
Upvotes: 0