0

I have a bluetooth device that triggers location services in my app when a button is pressed. And location services do run, but only for about 8 seconds. I have an NSLog outputting Location Found in the didUpdateToLocation delegate method. It outputs that NSLog for only that 8 seconds.

When I put the app in the foreground, location services continue again. Here is how I initialize the location manager:

self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
[self.locationManager requestAlwaysAuthorization];
[self.locationManager requestWhenInUseAuthorization];
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[self.locationManager setAllowsBackgroundLocationUpdates:YES];
[self.locationManager allowsBackgroundLocationUpdates];

When button is pressed, I run this:

[self.locationManager startUpdatingLocation];
Chris
  • 495
  • 1
  • 8
  • 19
  • In order to start updating location in the background in a continual manner you must start significant location change monitoring while your app is in the foreground – Paulw11 Dec 05 '16 at 20:15
  • Just tested that and it worked, but then there's no way to do what I need to do with my app? At all? – Chris Dec 05 '16 at 20:30
  • Well, you just need to leave significant location updates on. It has a low energy impact compared to full GPS location updates – Paulw11 Dec 05 '16 at 20:32

1 Answers1

0

You need enabling the background mode (location), as long as your location-manager is capable to receive location-updates, your app will receive all bluetooth data.

As @Paulw11 mentioned in comments, using significant-location-updates will drastically reduce battery usage.

Here is the link to Apple guide.

Here is the link to a question related to getting location updates in background.

Community
  • 1
  • 1
Zee
  • 1,865
  • 21
  • 42