In my application, I try to get new content and update it, even if my application is in standby mode. For this, I want to use the new multitasking function of iOS 7.
First of all, I turned on the background selection by adding the fetch
key to UIBackgroundModes
in Info.plist.
Then I set the minimum background fetch interval in AppDelegate:
[app setMinimumBackgroundFetchInterval: UIApplicationBackgroundFetchIntervalMinimum]
And the completion of the implementation:
(void) application : (UIApplication *)application performFetchWithCompletionHandler:(void(^) (UIBackgroundFetchResult))completionHandler
Now I have to use NSURLSession
to achieve what I want to do: - check for new image files on the server; - if YES, download it - a push notification informing the user about the availability of new content.
I will try something like this in performFetchWithCompletionHandler:
::
NSURLSession* session = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration backgroundSessionConfiguration:@"download"]]; [session downloadTaskWithRequest:<#(NSURLRequest *)#> completionHandler:<#^(NSURL *location, NSURLResponse *response, NSError *error)completionHandler#>]
But I do not like NSURLSession. If anyone has sample code to use it, I will be very happy to try it.
Tai, Pebi
Pebie source share