core location best practices - apple developer...continuous location in the background location...

163
© 2016 Apple Inc. All rights reserved. Redistribution or public display not permitted without written permission from Apple. Privacy and power System Frameworks #WWDC16 Session 716 Core Location Best Practices Brad Jensen Apple Inc

Upload: others

Post on 11-Jun-2020

23 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

© 2016 Apple Inc. All rights reserved. Redistribution or public display not permitted without written permission from Apple.

Privacy and power

System Frameworks #WWDC16

Session 716

Core Location Best Practices

Brad Jensen Apple Inc

Page 2: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

The Schedule

Page 3: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

The Schedule

Major Features

Page 4: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

The Schedule

Major FeaturesBest Practices

Page 5: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Major Features

Page 6: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Authorization

Page 7: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Authorization

Required to access location

Page 8: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Authorization

Required to access location

Page 9: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Authorization

Required to access locationWhen-in-use

Page 10: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Authorization

Required to access locationWhen-in-use• requestWhenInUseAuthorization

Page 11: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Authorization

Required to access locationWhen-in-use• requestWhenInUseAuthorization

Always

Page 12: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Authorization

Required to access locationWhen-in-use• requestWhenInUseAuthorization

Always• requestAlwaysAuthorization

Page 13: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Authorization

Required to access locationWhen-in-use• requestWhenInUseAuthorization

Always• requestAlwaysAuthorization

Page 14: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

When-in-use Authorization

Page 15: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

When-in-use Authorization

Foreground

Page 16: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

When-in-use Authorization

ForegroundBlue bar

Page 17: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

When-in-use Authorization

ForegroundBlue barWatchConnectivity

Page 18: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Standard Location

Page 19: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Standard Location

Single location• requestLocation

Page 20: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Standard Location

Single location• requestLocation

Continuous location• startUpdatingLocation

Page 21: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Standard Location

Single location• requestLocation

Continuous location• startUpdatingLocation• stopUpdatingLocation

Page 22: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Standard Location

Single location• requestLocation

Continuous location• startUpdatingLocation• stopUpdatingLocation

Features

Page 23: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Standard Location

Single location• requestLocation

Continuous location• startUpdatingLocation• stopUpdatingLocation

Features• Deferred updates

Page 24: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Standard Location

Single location• requestLocation

Continuous location• startUpdatingLocation• stopUpdatingLocation

Features• Deferred updates• Automatic pausing

Page 25: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Continuous Location in the Background

Page 26: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Continuous Location in the Background

Location updates and app continue running

Page 27: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Continuous Location in the Background

Location updates and app continue runningWhen-in-use authorized apps get a blue bar

Page 28: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Continuous Location in the Background

Location updates and app continue runningWhen-in-use authorized apps get a blue barStop when done

Page 29: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Continuous Location in the Background

Location updates and app continue runningWhen-in-use authorized apps get a blue barStop when doneRequirements

Page 30: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Continuous Location in the Background

Location updates and app continue runningWhen-in-use authorized apps get a blue barStop when doneRequirements• Enable background location in

information property list

Page 31: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Continuous Location in the Background

Location updates and app continue runningWhen-in-use authorized apps get a blue barStop when doneRequirements• Enable background location in

information property list• Set allowsBackgroundLocationUpdates

Page 32: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Continuous Location in the Background

Location updates and app continue runningWhen-in-use authorized apps get a blue barStop when doneRequirements• Enable background location in

information property list• Set allowsBackgroundLocationUpdates• Start continuous location updates in foreground

Page 33: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Standard Location in the Background

Page 34: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Standard Location in the Background

Start in background

Page 35: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Standard Location in the Background

Start in backgroundAlways authorization

Page 36: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Standard Location in the Background

Start in backgroundAlways authorizationNo extra runtime

Page 37: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Region Monitoring

Page 38: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Region Monitoring

Monitor for specific locations

Page 39: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Region Monitoring

Monitor for specific locationsContinues when app is suspended

Page 40: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Region Monitoring

Monitor for specific locationsContinues when app is suspendedTwo variants

Page 41: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Region Monitoring

Monitor for specific locationsContinues when app is suspendedTwo variants• Circular Region

Page 42: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Region Monitoring

Monitor for specific locationsContinues when app is suspendedTwo variants• Circular Region• Beacon Region

Page 43: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Region Monitoring

Monitor for specific locationsContinues when app is suspendedTwo variants• Circular Region• Beacon Region

Limited resource

Page 44: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Region Monitoring

Monitor for specific locationsContinues when app is suspendedTwo variants• Circular Region• Beacon Region

Limited resourceStart with startMonitoring(for:)

Page 45: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Region Monitoring

Monitor for specific locationsContinues when app is suspendedTwo variants• Circular Region• Beacon Region

Limited resourceStart with startMonitoring(for:)Stop with stopMonitoring(for:)

Page 46: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

TriggersRegion Monitoring

Page 47: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

TriggersRegion Monitoring

Notifications• UNLocationNotificationTrigger

Page 48: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

TriggersRegion Monitoring

Notifications• UNLocationNotificationTrigger

Introduction to Notifications Pacific Heights Wednesday 9:00AM

Page 49: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

TriggersRegion Monitoring

Notifications• UNLocationNotificationTrigger

HomeKit• HMLocationEvent

Introduction to Notifications Pacific Heights Wednesday 9:00AM

Page 50: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

TriggersRegion Monitoring

Notifications• UNLocationNotificationTrigger

HomeKit• HMLocationEvent

When-in-use authorization

Introduction to Notifications Pacific Heights Wednesday 9:00AM

Page 51: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Beacon Ranging

Page 52: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Beacon Ranging

UUID, major ID, and minor ID

Page 53: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Beacon Ranging

UUID, major ID, and minor IDRange to beacons

Page 54: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Beacon Ranging

UUID, major ID, and minor IDRange to beaconsNo extra runtime

Page 55: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Aside

https://developer.apple.com/ibeacon/

Page 56: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Significant Location Change Monitoring

Page 57: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Significant Location Change Monitoring

Monitor for large changes in location

Page 58: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Significant Location Change Monitoring

Monitor for large changes in locationUseful, but niche

Page 59: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Significant Location Change Monitoring

Monitor for large changes in locationUseful, but nicheConsider Visit Monitoring

Page 60: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Visit Monitoring

Page 61: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Visit Monitoring

Monitor for places of interest to the user

Page 62: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Visit Monitoring

Monitor for places of interest to the userSuitable for all-day use

Page 63: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Visit Monitoring

Monitor for places of interest to the userSuitable for all-day useContinues when app is suspended

Page 64: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Visit Monitoring

Monitor for places of interest to the userSuitable for all-day useContinues when app is suspendedStart with startMonitoringVisits

Page 65: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Visit Monitoring

Monitor for places of interest to the userSuitable for all-day useContinues when app is suspendedStart with startMonitoringVisitsStop with stopMonitoringVisits

Page 66: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Geocoding

Page 67: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Geocoding

Address to coordinates

Page 68: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Geocoding

Address to coordinatesCoordinates to address

Page 69: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Geocoding

Address to coordinatesCoordinates to addressAuthorization is not required

Page 70: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Geocoding

Address to coordinatesCoordinates to addressAuthorization is not requiredRate limiting

Page 71: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Geocoding

Address to coordinatesCoordinates to addressAuthorization is not requiredRate limiting• Cache results

Page 72: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Geocoding

Address to coordinatesCoordinates to addressAuthorization is not requiredRate limiting• Cache results• One request per user action

Page 73: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Which Authorization Level?

Page 74: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Which Authorization Level?

When-in-use Always

Page 75: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Which Authorization Level?

When-in-use Always

Standard Location ✓ ✓

Background Location Session ✓ ✓

Beacon Ranging ✓ ✓

Page 76: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Which Authorization Level?

When-in-use Always

Standard Location ✓ ✓

Background Location Session ✓ ✓

Beacon Ranging ✓ ✓

Region Monitoring ✓

Visit Monitoring ✓

Significant Location Change Monitoring ✓

Page 77: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Availability

Page 78: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Availability

Standard Location

Background Location Session

Beacon Ranging

Region Monitoring

Visit Monitoring

Significant Location Change Monitoring

Geocoding

Page 79: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Availability

Standard Location

Background Location Session

Beacon Ranging

Region Monitoring

Visit Monitoring

Significant Location Change Monitoring

Geocoding

iOS

Page 80: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Availability

Standard Location

Background Location Session

Beacon Ranging

Region Monitoring

Visit Monitoring

Significant Location Change Monitoring

Geocoding

iOS

macOS

N/A

CircularRegions

Page 81: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Availability

Standard Location

Background Location Session

Beacon Ranging

Region Monitoring

Visit Monitoring

Significant Location Change Monitoring

Geocoding

iOS

macOS

N/A

CircularRegions

watchOS

Page 82: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Availability

Standard Location

Background Location Session

Beacon Ranging

Region Monitoring

Visit Monitoring

Significant Location Change Monitoring

Geocoding

iOS

macOS

N/A

CircularRegions

watchOS

tvOSSingle

Location

Page 83: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Availability

iOS macOS watchOS tvOS

Standard Location ✓ ✓ ✓ SingleLocation

Background Location Session ✓ N/A

Beacon Ranging ✓

Region Monitoring ✓ CircularRegions

Visit Monitoring ✓

Significant Location Change Monitoring ✓ ✓

Geocoding ✓ ✓ ✓ ✓

Page 84: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Best Practices

Page 85: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Privacy

Page 86: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Privacy

The most important part

Page 87: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Privacy

The most important partYou must respect the user’s privacy

Page 88: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Privacy

The most important partYou must respect the user’s privacyYou must respect the user’s privacy

Page 89: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Privacy

The most important partYou must respect the user’s privacyYou must respect the user’s privacyDon’t ask for more than you need

Page 90: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Privacy

The most important partYou must respect the user’s privacyYou must respect the user’s privacyDon’t ask for more than you needMake it clear

Page 91: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

ContinuedPrivacy

Page 92: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

ContinuedPrivacy

Anonymize server queries

Page 93: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

ContinuedPrivacy

Anonymize server queriesUse file protection

Page 94: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Power

Page 95: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Power

Core Location’s power cost is highly variable

Page 96: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Power

Core Location’s power cost is highly variableUsers like their batteries

Page 97: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Power

Core Location’s power cost is highly variableUsers like their batteriesDesign with power in mind

Page 98: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Power

Core Location’s power cost is highly variableUsers like their batteriesDesign with power in mindUsing the right API matters

Page 99: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Which API?

Page 100: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Which API?

Now or Later?

Page 101: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Which API?

Now or Later?

RegionMonitoring

VisitMonitoring

Where?

Later

SpecificLocation

Any Location

Page 102: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Which API?

Now or Later?Now

Why?

RegionMonitoring

VisitMonitoring

Where?

Later

SpecificLocation

Any Location

Page 103: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Which API?

Now or Later?Now

Why?

Deferred Location Updates

Fitness

RegionMonitoring

VisitMonitoring

Where?

Later

SpecificLocation

Any Location

Page 104: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Which API?

Now or Later?Now

Why?

ContinuousLocation

Navigation

Deferred Location Updates

Fitness

RegionMonitoring

VisitMonitoring

Where?

Later

SpecificLocation

Any Location

Page 105: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Continuously Updating UI?

Yes

Other

Which API?

Now or Later?Now

Why?

ContinuousLocation

Navigation

Deferred Location Updates

Fitness

RegionMonitoring

VisitMonitoring

Where?

Later

SpecificLocation

Any Location

Page 106: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Continuously Updating UI?

Yes

Other

Which API?

Now or Later?Now

Why?

ContinuousLocation

Navigation

Deferred Location Updates

Fitness

RegionMonitoring

VisitMonitoring

Where?

Later

SpecificLocation

Any Location

Single Location

Recording a Track?

Yes No

No

Page 107: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Best practicesAuthorization

Page 108: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Best practicesAuthorization

Use when-in-use authorization when possible

Page 109: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Best practicesAuthorization

Use when-in-use authorization when possibleCommunicate

Page 110: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Best practicesAuthorization

Use when-in-use authorization when possibleCommunicate

Page 111: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Best practicesAuthorization

Use when-in-use authorization when possibleCommunicateDirect users to settings• UIApplicationOpenSettingsURLString

Page 112: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Best practicesAuthorization

Use when-in-use authorization when possibleCommunicateDirect users to settings• UIApplicationOpenSettingsURLString

Page 113: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Best practicesThreading

Page 114: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Best practicesThreading

CLLocationManager requires a runloop

Page 115: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Best practicesThreading

CLLocationManager requires a runloopYou can use CLLocationManager on the main thread

Page 116: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Best practicesThreading

CLLocationManager requires a runloopYou can use CLLocationManager on the main threadInteract with CLLocationManager from the thread it was created on

Page 117: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

// Requesting authorization

func requestAuthorization() {

let manager = CLLocationManager()

manager.requestWhenInUseAuthorization()

}

Page 118: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

// Requesting authorization

func requestAuthorization() {

let manager = CLLocationManager()

manager.requestWhenInUseAuthorization()

}

Page 119: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

// Requesting authorization

class LocationAuthorizationRequester {

static let manager = CLLocationManager()

func requestAuthorization() {

LocationAuthorizationRequester.manager.requestWhenInUseAuthorization()

}

}

Page 120: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

// Requesting authorization

class LocationAuthorizationRequester {

static let manager = CLLocationManager()

func requestAuthorization() {

LocationAuthorizationRequester.manager.requestWhenInUseAuthorization()

}

}

Page 121: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

// Requesting authorization

class LocationAuthorizationRequester {

static let manager = CLLocationManager()

func requestAuthorization() {

LocationAuthorizationRequester.manager.requestWhenInUseAuthorization()

}

}

Page 122: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

// Requesting authorization

class ViewController: UIViewController {

let manager = CLLocationManager()

func requestAuthorization() {

self.manager.requestWhenInUseAuthorization()

}

// ...

}

Page 123: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

// Requesting authorization

class ViewController: UIViewController {

let manager = CLLocationManager()

func requestAuthorization() {

self.manager.requestWhenInUseAuthorization()

}

// ...

}

Page 124: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

// Requesting authorization

class ViewController: UIViewController {

let manager = CLLocationManager()

func requestAuthorization() {

self.manager.requestWhenInUseAuthorization()

}

// ...

}

Page 125: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Best practicesStandard Location

Page 126: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Best practicesStandard Location

Use requestLocation

Page 127: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Best practicesStandard Location

Use requestLocationSet desiredAccuracy property

Page 128: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Best practicesStandard Location

Use requestLocationSet desiredAccuracy propertyEnable automatic pausing

Page 129: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Best practicesStandard Location

Use requestLocationSet desiredAccuracy propertyEnable automatic pausingUse deferred location updates

Page 130: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Best practicesStandard Location

Use requestLocationSet desiredAccuracy propertyEnable automatic pausingUse deferred location updatesEnergy Log Instrument

Page 131: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Best practicesStandard Location

Use requestLocationSet desiredAccuracy propertyEnable automatic pausingUse deferred location updatesEnergy Log InstrumentSet allowsBackgroundLocationUpdates

Page 132: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Best practicesStandard Location

Use requestLocationSet desiredAccuracy propertyEnable automatic pausingUse deferred location updatesEnergy Log InstrumentSet allowsBackgroundLocationUpdates

Page 133: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Best practicesStandard Location

Use requestLocationSet desiredAccuracy propertyEnable automatic pausingUse deferred location updatesEnergy Log InstrumentSet allowsBackgroundLocationUpdates

Page 134: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Best practicesMonitoring APIs

Page 135: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Best practicesMonitoring APIs

Use a single CLLocationManager

Page 136: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Best practicesMonitoring APIs

Use a single CLLocationManagerMonitoring continues until explicitly stopped

Page 137: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Best practicesMonitoring APIs

Use a single CLLocationManagerMonitoring continues until explicitly stoppedStop monitoring on launch if you’re unsure of your state

Page 138: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Best practicesMonitoring APIs

Use a single CLLocationManagerMonitoring continues until explicitly stoppedStop monitoring on launch if you’re unsure of your state

let manager = CLLocationManager()

manager.stopMonitoringVisits()

manager.stopMonitoringSignificantLocationChanges()

for region in manager.monitoredRegions {

manager.stopMonitoring(for: region)

}

Page 139: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Indoor Location

Page 140: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Indoor Location

Automatic

Page 141: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Indoor Location

Automaticmapsconnect.apple.com

Page 142: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Indoor Location

Automaticmapsconnect.apple.comBeacon region monitoring

Page 143: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

watchOS

Page 144: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

watchOS

iPhone automatically assists

Page 145: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

watchOS

iPhone automatically assistsWhen-in-use authorization

Page 146: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

watchOS

iPhone automatically assistsWhen-in-use authorizationstartUpdatingLocation is available*

*startUpdatingLocation will be available in a future seed

Page 147: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

watchOS

iPhone automatically assistsWhen-in-use authorizationstartUpdatingLocation is available*

*startUpdatingLocation will be available in a future seed

Building Great Workout Apps Pacific Heights Friday 11:00AM

Page 148: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

macOS

Page 149: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

macOS

Always authorization

Page 150: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

macOS

Always authorizationAutomatic prompting

Page 151: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

macOS

Always authorizationAutomatic promptingUse requestLocation

Page 152: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

tvOS

Page 153: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

tvOS

You have• Single location• Geocoding• MapKit

Page 154: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

tvOS

You have• Single location• Geocoding• MapKit

Respect the user’s privacy

Page 155: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Best Practices

Page 156: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Best Practices

Respect the user’s privacy

Page 157: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Best Practices

Respect the user’s privacyConserve power

Page 158: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Best Practices

Respect the user’s privacyConserve powerUse the right API

Page 159: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Best Practices

Respect the user’s privacyConserve powerUse the right APILook at Potloc

Page 160: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

More Information

https://developer.apple.com/wwdc16/716

Page 161: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Related Sessions

What's New in watchOS 3 Presidio Tuesday 5:00PM

Introduction to Notifications Pacific Heights Wednesday 9:00AM

Building Great Workout Apps Pacific Heights Friday 11:00AM

Page 162: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when

Labs

Core Location Lab Frameworks Lab C Friday 12:30PM

Notifications Lab Graphics, Games and Media Lab B Friday 9:00AM

HomeKit Lab Frameworks Lab A Friday 11:30AM

Page 163: Core Location Best Practices - Apple Developer...Continuous Location in the Background Location updates and app continue running When-in-use authorized apps get a blue bar Stop when