Question

In my application I try to fetch new content and keep it up to date even if my app is in standby mode. For that I want to use new multitasking iOS 7 feature.

First of all I've enable background fetch by adding the key fetch to UIBackgroundModes in Info.plist.

Then, I've set a minimum background fetch interval in AppDelegate:

[app setMinimumBackgroundFetchInterval: UIApplicationBackgroundFetchIntervalMinimum]

And finaly implement :

(void) application : (UIApplication *)application performFetchWithCompletionHandler:(void(^) (UIBackgroundFetchResult))completionHandler 

Now I should use NSURLSession to achieve what I want to do : - check if new image files are availiable on a server - if YES, download it - push notification to inform user that new content is availiable

I will try something like this in the performFetchWithCompletionHandler: :

NSURLSession* session = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration backgroundSessionConfiguration:@"download"]];
[session downloadTaskWithRequest:<#(NSURLRequest *)#> completionHandler:<#^(NSURL *location, NSURLResponse *response, NSError *error)completionHandler#>]

But I'm not comfortable with NSURLSession. If someone has sample code to use it, I will be very happy to try it.

Ty, Pebie

Was it helpful?

Solution

there is sample code here: https://developer.apple.com/downloads/index.action download the iOS_SimpleBackgroundTransfer sample.

OTHER TIPS

In your performFetchWithCompletionHandler:, check to see if new images are available using NSURLRequest/NSURLConnection as you're comfortable with.

If you do have images to download, create a NSURLSession with the backgroundSessionConfiguration to download the images.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top