Martin Sjöblom
Martin Sjöblom

Reputation: 141

startMonitoringSignificantLocationChanges() not working with swift in xcode 6 Beta2?

I'm trying to implement a more efficient background handling of my location dependent application and also learn some Swift while doing so.

I noticed (the hard way) that I couldn't get locations to work at all in the first Beta but switching to Beta2 of xcode solved that part.

In the setup of my location handling I initiate a LocationManager with code like this (I want to be able to switch to high resolution and even start in high mode):

locationManager.delegate = self
locationManager.distanceFilter = kCLDistanceFilterNone
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.requestWhenInUseAuthorization()
locationManager.startMonitoringSignificantLocationChanges()

locationManager.startUpdatingLocation();

And then handle switching with code like:

if (highResolutionSwitch.on) {
  println("Switching to high resolution");
  locationManager.stopMonitoringSignificantLocationChanges();
  locationManager.startUpdatingLocation();
} else {
  println("Switching to low resolution");
  locationManager.stopUpdatingLocation();
  locationManager.startMonitoringSignificantLocationChanges();
}

When in "high"-mode I receive locations in my didUpdateLocations() method but NEVER anything in "low"-mode. Is it the beta nature of the xcode/swift-environment or am I missing something?

Upvotes: 1

Views: 5175

Answers (1)

Martin Sjöblom
Martin Sjöblom

Reputation: 141

Problem found!

The problem was that the call to locationManager.requestWhenInUseAuthorization() was not enough. This doesn't enable significant location changes. Changing that line to locationManager.requestAlwaysAuthorization() made at least the simulator to give me one location (although no new location when I changed the position).

I will redeploy my app and see if it works IRL.

I also needed to reinstall the app on the simulator so that the "allow" question was given again.

Upvotes: 10

Related Questions