4

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

4
  • Be aware that iOS 7 and Xcode 5 are still under NDA, which restricts you from talking about them outside of the official Apple Developers forum. This might be why you will not get any answers for your question.
    – rckoenes
    Sep 9, 2013 at 13:58
  • Ok I didn't know it :(
    – Pebie
    Sep 9, 2013 at 14:06
  • Well you agreed to NDA when you downloaded the iOS 7 SDK.
    – rckoenes
    Sep 9, 2013 at 14:12
  • I agree with you but you know how it goes :) I will delete this post.
    – Pebie
    Sep 9, 2013 at 14:45

2 Answers 2

3

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

0

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.

1
  • It seems a little unreasonable to use two separate APIs for HTTP requests; just use NSURLSession for it all Oct 21, 2013 at 11:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.