Reputation: 31
i'm developing an iPhone application, which should update the gps location and deliver it to my server every 15 minutes, when the app is in background or in foreground.
I am using a NSTimer which calls a method every second to do several things (My Method does only update the location every 15 minutes) I tried it in my ViewController to keep my Timer in background running by using this:
(...)
TimerTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler: ^{
}];
CurrentTimer = [NSTimer scheduledTimerWithTimeInterval: 1.0 target: self selector: @selector(timerTicked:) userInfo: nil repeats: YES];
(...)
But the problem is that after approximately 10 minutes my timer seems to stop, when the app is in background.
Is there any possibility to do it right?
Thank you
Upvotes: 2
Views: 2622
Reputation: 7226
You can use an NSTimer
in the AppDelegate
or you can add an NSNotification
. Both will be useful.
Please view the following link:-
How do I get a background location update every n minutes in my iOS application?
Upvotes: 2