Reputation: 8589
I'm using Parse.com as my backend and want to update something in the database (a badge count) when the app enters the background. I am using this code below. I understand that this only allows for five seconds of operation time though. Is there a way to extend this time?
- (void)applicationDidEnterBackground:(UIApplication *)application {
PFInstallation *currentInstallation = [PFInstallation currentInstallation];
curentInstallation.badge = self.messageCount;
currentInstallation.badge = 0;
[currentInstallation saveEventually];
}
I have also read: If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. By supporting background execution does it mean having the values enabled in the Plist and the user allows for background execution or does it refer to old versions of iOS that don't do backgrounding? Any pointers on this would be great. thanks
Upvotes: 1
Views: 65
Reputation: 4331
You should look at:
The example code shows you how to create a background task. In that you could use the normal Parse API with callback. Inside this callback, you have to call
[application endBackgroundTask:bgTask];
bgTask = UIBackgroundTaskInvalid;
To let iOS know, when you're done.
You should also make use of backgroundTimeRemaining and schedule a timer fire event before you don't have any time left and make sure you call saveEventually
, so parse can (in this case) at least save the changes the next time the user opens your app!
Upvotes: 1