WWDC 2015

What's New in Core Location

Many apps requires user's location to perform the required features or enhance the user experiences. Every year of WWDC provides better funtionailty for developers to access and provides more control for the users to handle app-wise locational permissions.

  • authorization
  • location updates
  • indoor updates
    • more accurate
    • faster detection
  • region monitoring
    • iBeacon
    • Geographic
  • Visit monitoring
  • Sig. Location change/ Geocoding/ Reverse-Geocoding
  • Background location
    • iOS 4+ background mode
    • Add UIBackgroundModes
    • iOS 9 simplifty the workflow
      • Lower stake
      • Loose coupling
      • allowsBackgroundLocationUpdates property per CLLocationManager
        • Default values: NO
        • when finish : set it to NO And not tracking the location
        • MUST UPDATE FOR IOS 9
        • check with -responsdToSelector:
        • Audible cue? Related session: What's new in core audio
  • Single location
    • requestLocation by giving desiredAccuracy to locationManager .
    • Automatically (so you dont need to monitor start/stop by yourself, system handled for you)
      • start (exculsive only one at a time)
      • threholds internally
      • calls delegate once locationManager:didUpdateLocations: or locationManager:didFailWithError
      • stop
// from : http://nshipster.com/ios9/
class ViewController : UIViewController, CLLocationManagerDelegate {
    let locationManager = CLLocationManager()
    // ...

    override func viewDidLoad() {
        super.viewDidLoad()

        locationManager.delegate = self
        locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters
        locationManager.requestLocation()
    }

   // MARK: - CLLocationManagerDelegate

    func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
        if let location = locations.first {
            print("Current location: \(location)")
        } else {
            // ...
        }
    }

    func locationManager(manager: CLLocationManager, didFailWithError error: NSError) {
        print("Error finding location: \(error.localizedDescription)")
    }
}
  • Authorization
  • Apple Watch: Best practices
    • Authorization applies to both Watch and iPhone
      • requestWhenInUserAuthorization
      • requestAlwaysAutherization
iOS WhenInUse Always
Location YES YES
Background(continuous) YES YES
Background(intermittent) NO YES
Monitor Local notifiation YES
watchOS WhenInUse Always
Location Single Single
Background(continuous) NO NO
Background(intermittent) NO Single
Monitor NO NO
  • location in use if
    • blue bar
    • foreground
    • handling message from apple watch

Accuracy with iPhone

  • requestLocation Even indoor

Accuracy without iPhone

  • requestLocation kCLLocationAccurayHundredMeters
  • Best effort
  • Cooperation
    • if the app need:
      • continuous background monitoring
      • Region Monitoring
      • Anything availabe on iOS but not allowed on watchOS
      • User WCSession Related session : Introducing Watch Connectivity
        • sendMessage:replyHandler:errorHanlder: (watch to phone)
          • remember set allowsBackgroundLocationUpdates yes to get location
        • updateApplicationContent: (iPhone to Apple Watch)
          • Last one kept until the watch app is running
          • -allowDeferredLocationUpdateUntilTraveled:timeout: use this latency to update location based on distance traveled or time passed.