For to keep a long term timer in ios you cannot rely on default NSTimers or else.When the application goes in background you have to create a background execution task.
Within this task you should create a NSTimer with a scheduled timetick. (maybe set if for an hour later etc)
then when the timer executes stop the background task and do your business methods.
- (void)applicationDidEnterBackground:(UIApplication *)application
{
UIApplication* app = [UIApplication sharedApplication];
bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
[app endBackgroundTask:bgTask];
bgTask = UIBackgroundTaskInvalid;
}];
// Start the long-running task and return immediately.
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
// Do the work associated with the task.
[self startTimer]; //Set nstimer..... scheduled one.
[app endBackgroundTask:bgTask];
bgTask = UIBackgroundTaskInvalid;
});
}
Cagdas
Hiç yorum yok:
Yorum Gönder