1

How can i stop and start the GPS tracking when an application running in background. i Can able to stop tracking in the application, but didn't got any way to start the application. I looking for answers for followings.

1.whether i can use push notification silently to start GPS tracking. 2.I tried with local notification, but it require user interaction to start the process. Is there any best ways to do this.

My problem: Initially i can able start tracking the user location and can stop that after some time in background. I wanted to start the tracking next day. Im looking for a way to start tracking in background.

Actually my application is basically the location tracking application. if the launches the application, the app starts tracking until the time 8:00 pm (stops automatically). Again started tracking next day 8:00 am.

mfaani
  • 33,269
  • 19
  • 164
  • 293
Muruganandham K
  • 5,271
  • 5
  • 34
  • 62
  • May be this is what you are looking for [Automatic ON/OFF the GPS tracking in an app running in Background][1] [1]: http://stackoverflow.com/questions/10235203/getting-user-location-every-n-minutes-after-app-goes-to-background – NSSwift Jul 07 '15 at 05:08
  • @AngelVasa i can able to update location and stop the tracking perfectly. But cant able to re-enable the tracking next day. – Muruganandham K Jul 07 '15 at 05:14

2 Answers2

1

If you started location updates while your app is running in background, these updates will not last longer than whatever time iOS granted for your background task (currently 180 sec).

Location updates must be started while the app is active, doing this ensures the updates keep coming even after your app goes to background, assuming you configured your app background modes properly - see Capabilities/Background Modes/Location updates in Xcode.

Even though, if your app is terminated, the delivery of new location events stops altogether.

If you want to temporary suppress standard location updates, please use

allowDeferredLocationUpdatesUntilTraveled:timeout:

When updates are deferred, GPS receiver is still powered, but no CPU activity happens, as the receiver will not trigger events. I did not test power consumption in this mode myself, but people mention ~2% battery drain per hour.

Alex Pavlov
  • 991
  • 6
  • 9
0

Have you tried this

-(void)applicationDidEnterBackground {
  [self.locationManager stopUpdatingLocation];

  UIApplication* app = [UIApplication sharedApplication];

  bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
    [app endBackgroundTask:bgTask];
    bgTask = UIBackgroundTaskInvalid;
  }];

  self.timer = [NSTimer scheduledTimerWithTimeInterval:intervalBackgroundUpdate
                                                target:self.locationManager
                                              selector:@selector(startUpdatingLocation)
                                              userInfo:nil
                                               repeats:YES];
}

Set intervalBackground Update to 1 day

NSSwift
  • 215
  • 2
  • 8
  • i need to update the location on exactly tomorrow morning 8 am. So that i can set fireDate to execute this timer. note that the location update will stopped by today 8pm – Muruganandham K Jul 07 '15 at 05:53
  • It should work, if you are not doing any other mistakes ;) @iTroyd23 – NSSwift Jul 07 '15 at 06:01
  • Actually my application is basically the location tracking application. if the launches the application, the app starts tracking until the time 8:00 pm (stops automatically). Again started tracking next day 8:00 am. – Muruganandham K Jul 07 '15 at 06:13