Skip to content

Instantly share code, notes, and snippets.

@SteveTrewick
Last active October 16, 2015 15:15
Show Gist options
  • Save SteveTrewick/90540473a52a313c82b8 to your computer and use it in GitHub Desktop.
Save SteveTrewick/90540473a52a313c82b8 to your computer and use it in GitHub Desktop.
Swift ios9 background core location
/*
In your .plist :
<key>UIBackgroundModes</key>
<array>
<string>location</string>
</array>
...
<key>UIRequiredDeviceCapabilities</key>
<array>
...
<string>gps</string>
<string>location-services</string>
</array>
...
<key>NSLocationWhenInUseUsageDescription</key>
<string>App requires access to GPS when in use</string>
...
*/
// given self.locman is an initialised CLLocationManager
self.locman.requestWhenInUseAuthorization()
self.locman.desiredAccuracy = kCLLocationAccuracyBest
self.locman.activityType = .Fitness
self.locman.allowsBackgroundLocationUpdates = true // << THIS, or you won't get any background time
self.locman.startUpdatingLocation()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment