Top Banner
These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 303 Jay Bruins Software Engineer Staying on Track with Location Services
232

Session 303 - Staying on Track With Location Services

Dec 01, 2015

Download

Documents

foufoutos73

Session 303 - Staying on Track With Location Services
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Session 303 - Staying on Track With Location Services

These are confidential sessions—please refrain from streaming, blogging, or taking pictures

Session 303Jay BruinsSoftware Engineer

Staying on Track withLocation Services

Page 2: Session 303 - Staying on Track With Location Services

What We’ll Cover

Page 3: Session 303 - Staying on Track With Location Services

What We’ll Cover

• Overview

Page 4: Session 303 - Staying on Track With Location Services

What We’ll Cover

• Overview• Improvements

Page 5: Session 303 - Staying on Track With Location Services

What We’ll Cover

• Overview• Improvements• New APIs

Page 6: Session 303 - Staying on Track With Location Services

What We’ll Cover

• Overview• Improvements• New APIs• Tips, tricks, and myths

Page 7: Session 303 - Staying on Track With Location Services

RefresherCoreLocation

Page 8: Session 303 - Staying on Track With Location Services

Why Is Location Powerful?

Page 9: Session 303 - Staying on Track With Location Services

Location provides contextWhy Is Location Powerful?

Page 10: Session 303 - Staying on Track With Location Services

Location provides contextWhy Is Location Powerful?

• iOS: Inherently mobile

Page 11: Session 303 - Staying on Track With Location Services

Location provides contextWhy Is Location Powerful?

• iOS: Inherently mobile• Enhances the user experience

Page 12: Session 303 - Staying on Track With Location Services

Location provides contextWhy Is Location Powerful?

• iOS: Inherently mobile• Enhances the user experience• More intuitive apps

Page 13: Session 303 - Staying on Track With Location Services

Location provides contextWhy Is Location Powerful?

• iOS: Inherently mobile• Enhances the user experience• More intuitive apps• Enables new use cases

Page 14: Session 303 - Staying on Track With Location Services

Location Technologies

Page 15: Session 303 - Staying on Track With Location Services

Location Technologies

• Cellular positioning

Page 16: Session 303 - Staying on Track With Location Services

Location Technologies

• Cellular positioning• Wi-Fi positioning

Page 17: Session 303 - Staying on Track With Location Services

Location Technologies

• Cellular positioning• Wi-Fi positioning• Global Navigation Satellite Systems (GNSS)

Page 18: Session 303 - Staying on Track With Location Services

Location Technologies

• Cellular positioning• Wi-Fi positioning• Global Navigation Satellite Systems (GNSS)

■ NavStar (GPS)

Page 19: Session 303 - Staying on Track With Location Services

Location Technologies

• Cellular positioning• Wi-Fi positioning• Global Navigation Satellite Systems (GNSS)

■ NavStar (GPS)■ GLONASS

Page 20: Session 303 - Staying on Track With Location Services

CoreLocation API

Page 21: Session 303 - Staying on Track With Location Services

CoreLocation API

- (void)setupLocation{! self.manager = [CLLocationManager new];! self.manager.delegate = self;! self.manager.desiredAccuracy = kCLLocationAccuracyBestForNavigation;}- (void)startLocation{! [self.manager startUpdatingLocation];}- (void)locationManager:(CLLocationManager *)manager! didUpdateToLocation:(CLLocation *)newLocation! ! ! fromLocation:(CLLocation *)oldLocation{! self.mapView.userPosition = newLocation;}

Page 22: Session 303 - Staying on Track With Location Services

CoreLocation API

- (void)setupLocation{! self.manager = [CLLocationManager new];! self.manager.delegate = self;! self.manager.desiredAccuracy = kCLLocationAccuracyBestForNavigation;}- (void)startLocation{! [self.manager startUpdatingLocation];}- (void)locationManager:(CLLocationManager *)manager! didUpdateToLocation:(CLLocation *)newLocation! ! ! fromLocation:(CLLocation *)oldLocation{! self.mapView.userPosition = newLocation;}

Page 23: Session 303 - Staying on Track With Location Services

CoreLocation API

- (void)setupLocation{! self.manager = [CLLocationManager new];! self.manager.delegate = self;! self.manager.desiredAccuracy = kCLLocationAccuracyBestForNavigation;}- (void)startLocation{! [self.manager startUpdatingLocation];}- (void)locationManager:(CLLocationManager *)manager! didUpdateToLocation:(CLLocation *)newLocation! ! ! fromLocation:(CLLocation *)oldLocation{! self.mapView.userPosition = newLocation;}

Page 24: Session 303 - Staying on Track With Location Services

CoreLocation API

- (void)setupLocation{! self.manager = [CLLocationManager new];! self.manager.delegate = self;! self.manager.desiredAccuracy = kCLLocationAccuracyBestForNavigation;}- (void)startLocation{! [self.manager startUpdatingLocation];}- (void)locationManager:(CLLocationManager *)manager! didUpdateToLocation:(CLLocation *)newLocation! ! ! fromLocation:(CLLocation *)oldLocation{! self.mapView.userPosition = newLocation;}

Page 25: Session 303 - Staying on Track With Location Services

CoreLocation API

- (void)setupLocation{! self.manager = [CLLocationManager new];! self.manager.delegate = self;! self.manager.desiredAccuracy = kCLLocationAccuracyBestForNavigation;}- (void)startLocation{! [self.manager startUpdatingLocation];}- (void)locationManager:(CLLocationManager *)manager! didUpdateToLocation:(CLLocation *)newLocation! ! ! fromLocation:(CLLocation *)oldLocation{! self.mapView.userPosition = newLocation;}

Page 26: Session 303 - Staying on Track With Location Services

CoreLocation API

- (void)setupLocation{! self.manager = [CLLocationManager new];! self.manager.delegate = self;! self.manager.desiredAccuracy = kCLLocationAccuracyBestForNavigation;}- (void)startLocation{! [self.manager startUpdatingLocation];}- (void)locationManager:(CLLocationManager *)manager! didUpdateToLocation:(CLLocation *)newLocation! ! ! fromLocation:(CLLocation *)oldLocation{! self.mapView.userPosition = newLocation;}

Page 27: Session 303 - Staying on Track With Location Services

Improvements to Location ServicesWhat’s New?

Page 28: Session 303 - Staying on Track With Location Services

What’s New?

Page 29: Session 303 - Staying on Track With Location Services

What’s New?

• Improved accuracy

Page 30: Session 303 - Staying on Track With Location Services

What’s New?

• Improved accuracy• Improved availability

Page 31: Session 303 - Staying on Track With Location Services

What’s New?

• Improved accuracy• Improved availability• Lowered power consumption

Page 32: Session 303 - Staying on Track With Location Services

Improved Accuracy

Page 33: Session 303 - Staying on Track With Location Services
Page 34: Session 303 - Staying on Track With Location Services
Page 35: Session 303 - Staying on Track With Location Services
Page 36: Session 303 - Staying on Track With Location Services
Page 37: Session 303 - Staying on Track With Location Services
Page 38: Session 303 - Staying on Track With Location Services
Page 39: Session 303 - Staying on Track With Location Services

Wi-Fi–Aided Location

Page 40: Session 303 - Staying on Track With Location Services

Wi-Fi–Aided LocationReduced horizontal outliers

Page 41: Session 303 - Staying on Track With Location Services

Wi-Fi–Aided LocationReduced horizontal outliers

Page 42: Session 303 - Staying on Track With Location Services

Wi-Fi–Aided LocationReduced horizontal outliers

GNSSGNSS+WiFi

Page 43: Session 303 - Staying on Track With Location Services

Wi-Fi–Aided LocationReduced horizontal outliers

GNSSGNSS+WiFi

Page 44: Session 303 - Staying on Track With Location Services

Map-Aided Location

Page 45: Session 303 - Staying on Track With Location Services

Map-Aided Location

• Location and course

Page 46: Session 303 - Staying on Track With Location Services

Map-Aided Location

• Location and course• Driving

Page 47: Session 303 - Staying on Track With Location Services

Map-Aided Location

• Location and course• Driving• Vector map data

Page 48: Session 303 - Staying on Track With Location Services

Map-Aided Location

• Location and course• Driving• Vector map data• Improve if possible

Page 49: Session 303 - Staying on Track With Location Services

Improved Turns

Page 50: Session 303 - Staying on Track With Location Services

Improved Turns

Page 51: Session 303 - Staying on Track With Location Services

Improved Turns

Page 52: Session 303 - Staying on Track With Location Services

Improved Turns

Page 53: Session 303 - Staying on Track With Location Services

Improved Turns

Page 54: Session 303 - Staying on Track With Location Services

Do No Harm

Page 55: Session 303 - Staying on Track With Location Services

Do No Harm

Page 56: Session 303 - Staying on Track With Location Services

Do No Harm

Page 57: Session 303 - Staying on Track With Location Services

Do No Harm

Page 58: Session 303 - Staying on Track With Location Services

API Availability on OS X

Page 59: Session 303 - Staying on Track With Location Services

API Availability on OS X

• Geocoding

Page 60: Session 303 - Staying on Track With Location Services

API Availability on OS X

• Geocoding• Region monitoring

Page 61: Session 303 - Staying on Track With Location Services

Reverse GeocodingTransforms a coordinate into an address

Page 62: Session 303 - Staying on Track With Location Services

37.78338, -122.403354

Reverse GeocodingTransforms a coordinate into an address

Page 63: Session 303 - Staying on Track With Location Services

37.78338, -122.403354

Reverse GeocodingTransforms a coordinate into an address

800 Howard St.San Francisco, CA

Page 64: Session 303 - Staying on Track With Location Services

Forward GeocodingTransforms an address into a coordinate

Page 65: Session 303 - Staying on Track With Location Services

Forward GeocodingTransforms an address into a coordinate

800 Howard St.San Francisco, CA

Page 66: Session 303 - Staying on Track With Location Services

Forward GeocodingTransforms an address into a coordinate

37.78338, -122.403354800 Howard St.San Francisco, CA

Page 67: Session 303 - Staying on Track With Location Services

CLLocationCoordinate2D coord = CLLocationCoordinate2DMake(37.332426, -122.030404);CLRegion *region = [[CLRegion alloc] initCircularRegionWithCenter:coord radius:100.0 identifier:@”Apple Inc.”];

Starting Region Monitoring

<CLLocationManagerDelegate> CLLocationManager

Core Location FrameworkDelegate Object

startMonitoringForRegion:(CLRegion *)region;

Page 68: Session 303 - Staying on Track With Location Services

CLLocationManager

Core Location Framework

<CLLocationManagerDelegate>

Delegate Object

Receiving Region Monitoring Events

locationManager:didEnterRegion:

locationManager:didExitRegion:

Page 69: Session 303 - Staying on Track With Location Services

Reminders on OS X

Page 70: Session 303 - Staying on Track With Location Services

Example

Page 71: Session 303 - Staying on Track With Location Services

Example

- (void)installReminder{! NSString *address = @"2 Infinite Loop, Cupertino, CA 95014";! CLGeocoder *geocoder = [CLGeocoder new];! [geocoder geocodeAddressString:address! ! ! ! ! completionHandler: ^(NSArray *placemarks, NSError *error){! ! [self.locationManager startMonitoringForRegion:[placemark region]];! }];}- (void)locationManager:(CLLocationManager *)manager! ! didEnterRegion:(CLRegion *)region{! NSAlert *alert = [NSAlert new];! [alert setMessageText:@"Welcome to the Loop!"];! [alert runModal];}

Page 72: Session 303 - Staying on Track With Location Services

Example

- (void)installReminder{! NSString *address = @"2 Infinite Loop, Cupertino, CA 95014";! CLGeocoder *geocoder = [CLGeocoder new];! [geocoder geocodeAddressString:address! ! ! ! ! completionHandler: ^(NSArray *placemarks, NSError *error){! ! [self.locationManager startMonitoringForRegion:[placemark region]];! }];}- (void)locationManager:(CLLocationManager *)manager! ! didEnterRegion:(CLRegion *)region{! NSAlert *alert = [NSAlert new];! [alert setMessageText:@"Welcome to the Loop!"];! [alert runModal];}

Page 73: Session 303 - Staying on Track With Location Services

Example

- (void)installReminder{! NSString *address = @"2 Infinite Loop, Cupertino, CA 95014";! CLGeocoder *geocoder = [CLGeocoder new];! [geocoder geocodeAddressString:address! ! ! ! ! completionHandler: ^(NSArray *placemarks, NSError *error){! ! [self.locationManager startMonitoringForRegion:[placemark region]];! }];}- (void)locationManager:(CLLocationManager *)manager! ! didEnterRegion:(CLRegion *)region{! NSAlert *alert = [NSAlert new];! [alert setMessageText:@"Welcome to the Loop!"];! [alert runModal];}

Page 74: Session 303 - Staying on Track With Location Services

Example

- (void)installReminder{! NSString *address = @"2 Infinite Loop, Cupertino, CA 95014";! CLGeocoder *geocoder = [CLGeocoder new];! [geocoder geocodeAddressString:address! ! ! ! ! completionHandler: ^(NSArray *placemarks, NSError *error){! ! [self.locationManager startMonitoringForRegion:[placemark region]];! }];}- (void)locationManager:(CLLocationManager *)manager! ! didEnterRegion:(CLRegion *)region{! NSAlert *alert = [NSAlert new];! [alert setMessageText:@"Welcome to the Loop!"];! [alert runModal];}

Page 75: Session 303 - Staying on Track With Location Services

Example

- (void)installReminder{! NSString *address = @"2 Infinite Loop, Cupertino, CA 95014";! CLGeocoder *geocoder = [CLGeocoder new];! [geocoder geocodeAddressString:address! ! ! ! ! completionHandler: ^(NSArray *placemarks, NSError *error){! ! [self.locationManager startMonitoringForRegion:[placemark region]];! }];}- (void)locationManager:(CLLocationManager *)manager! ! didEnterRegion:(CLRegion *)region{! NSAlert *alert = [NSAlert new];! [alert setMessageText:@"Welcome to the Loop!"];! [alert runModal];}

Page 76: Session 303 - Staying on Track With Location Services

Example

- (void)installReminder{! NSString *address = @"2 Infinite Loop, Cupertino, CA 95014";! CLGeocoder *geocoder = [CLGeocoder new];! [geocoder geocodeAddressString:address! ! ! ! ! completionHandler: ^(NSArray *placemarks, NSError *error){! ! [self.locationManager startMonitoringForRegion:[placemark region]];! }];}- (void)locationManager:(CLLocationManager *)manager! ! didEnterRegion:(CLRegion *)region{! NSAlert *alert = [NSAlert new];! [alert setMessageText:@"Welcome to the Loop!"];! [alert runModal];}

Page 77: Session 303 - Staying on Track With Location Services

Example

- (void)installReminder{! NSString *address = @"2 Infinite Loop, Cupertino, CA 95014";! CLGeocoder *geocoder = [CLGeocoder new];! [geocoder geocodeAddressString:address! ! ! ! ! completionHandler: ^(NSArray *placemarks, NSError *error){! ! [self.locationManager startMonitoringForRegion:[placemark region]];! }];}- (void)locationManager:(CLLocationManager *)manager! ! didEnterRegion:(CLRegion *)region{! NSAlert *alert = [NSAlert new];! [alert setMessageText:@"Welcome to the Loop!"];! [alert runModal];}

Page 78: Session 303 - Staying on Track With Location Services

Example

- (void)installReminder{! NSString *address = @"2 Infinite Loop, Cupertino, CA 95014";! CLGeocoder *geocoder = [CLGeocoder new];! [geocoder geocodeAddressString:address! ! ! ! ! completionHandler: ^(NSArray *placemarks, NSError *error){! ! [self.locationManager startMonitoringForRegion:[placemark region]];! }];}- (void)locationManager:(CLLocationManager *)manager! ! didEnterRegion:(CLRegion *)region{! NSAlert *alert = [NSAlert new];! [alert setMessageText:@"Welcome to the Loop!"];! [alert runModal];}

Page 79: Session 303 - Staying on Track With Location Services

Wi-Fi Availability

Page 80: Session 303 - Staying on Track With Location Services

Wi-Fi Availability

Page 81: Session 303 - Staying on Track With Location Services

Wi-Fi Availability

Page 82: Session 303 - Staying on Track With Location Services
Page 83: Session 303 - Staying on Track With Location Services
Page 84: Session 303 - Staying on Track With Location Services

10× More Access Points

Page 85: Session 303 - Staying on Track With Location Services

10× More Access Points

60× More Coverage Area

Page 86: Session 303 - Staying on Track With Location Services

Wi-Fi Tile Advantages

Page 87: Session 303 - Staying on Track With Location Services

Wi-Fi Tile Advantages

• Instant locations (Passbook, Weather, etc.)

Page 88: Session 303 - Staying on Track With Location Services

Wi-Fi Tile Advantages

• Instant locations (Passbook, Weather, etc.)• Improved availability on Wi-Fi–only devices

Page 89: Session 303 - Staying on Track With Location Services

Wi-Fi Tile Advantages

• Instant locations (Passbook, Weather, etc.)• Improved availability on Wi-Fi–only devices

■ Region monitoring

Page 90: Session 303 - Staying on Track With Location Services

Wi-Fi Tile Advantages

• Instant locations (Passbook, Weather, etc.)• Improved availability on Wi-Fi–only devices

■ Region monitoring■ Photo geo-tagging

Page 91: Session 303 - Staying on Track With Location Services

Wi-Fi Tile Advantages

• Instant locations (Passbook, Weather, etc.)• Improved availability on Wi-Fi–only devices

■ Region monitoring■ Photo geo-tagging

• International 3G roaming

Page 92: Session 303 - Staying on Track With Location Services

Wi-Fi Tile Advantages

• Instant locations (Passbook, Weather, etc.)• Improved availability on Wi-Fi–only devices

■ Region monitoring■ Photo geo-tagging

• International 3G roaming• 10x better data usage

Page 93: Session 303 - Staying on Track With Location Services

API Changes

Page 94: Session 303 - Staying on Track With Location Services

Power

Page 95: Session 303 - Staying on Track With Location Services

Power

Page 96: Session 303 - Staying on Track With Location Services

Power

Page 97: Session 303 - Staying on Track With Location Services

Power

Page 98: Session 303 - Staying on Track With Location Services

The Problem

Page 99: Session 303 - Staying on Track With Location Services

The Problem

• App running indefinitely

Page 100: Session 303 - Staying on Track With Location Services

The Problem

• App running indefinitely• User not moving

Page 101: Session 303 - Staying on Track With Location Services

The Problem

• App running indefinitely• User not moving• Location not available

Page 102: Session 303 - Staying on Track With Location Services

The Problem

• App running indefinitely• User not moving• Location not available• Activity stopped

Page 103: Session 303 - Staying on Track With Location Services

AutoPause

Page 104: Session 303 - Staying on Track With Location Services

AutoPause

• App becomes pausable when backgrounded

Page 105: Session 303 - Staying on Track With Location Services

AutoPause

• App becomes pausable when backgrounded• Pause criteria

Page 106: Session 303 - Staying on Track With Location Services

AutoPause

• App becomes pausable when backgrounded• Pause criteria

■ User not moving

Page 107: Session 303 - Staying on Track With Location Services

AutoPause

• App becomes pausable when backgrounded• Pause criteria

■ User not moving■ Device cannot obtain a location fix

Page 108: Session 303 - Staying on Track With Location Services

AutoPause

• App becomes pausable when backgrounded• Pause criteria

■ User not moving■ Device cannot obtain a location fix■ User discontinues activity

Page 109: Session 303 - Staying on Track With Location Services

AutoPause API

Page 110: Session 303 - Staying on Track With Location Services

AutoPause API

• Enabled?

Page 111: Session 303 - Staying on Track With Location Services

AutoPause API

• Enabled?@property BOOL pausesLocationUpdatesAutomatically

Page 112: Session 303 - Staying on Track With Location Services

AutoPause API

• Enabled?@property BOOL pausesLocationUpdatesAutomatically

• Activity detection

Page 113: Session 303 - Staying on Track With Location Services

AutoPause API

• Enabled?@property BOOL pausesLocationUpdatesAutomatically

• Activity detection@property CLActivityType activityType

Page 114: Session 303 - Staying on Track With Location Services

AutoPause API

• Enabled?@property BOOL pausesLocationUpdatesAutomatically

• Activity detection@property CLActivityType activityType

CLActivityTypeVehicularNavigation

Page 115: Session 303 - Staying on Track With Location Services

AutoPause API

• Enabled?@property BOOL pausesLocationUpdatesAutomatically

• Activity detection@property CLActivityType activityType

CLActivityTypeVehicularNavigationCLActivityTypeFitness

Page 116: Session 303 - Staying on Track With Location Services

AutoPause API

• Enabled?@property BOOL pausesLocationUpdatesAutomatically

• Activity detection@property CLActivityType activityType

CLActivityTypeVehicularNavigationCLActivityTypeFitnessCLActivityTypeOther

Page 117: Session 303 - Staying on Track With Location Services

AutoPause API

• Enabled?@property BOOL pausesLocationUpdatesAutomatically

• Activity detection@property CLActivityType activityType

CLActivityTypeVehicularNavigationCLActivityTypeFitnessCLActivityTypeOther

• Handle pause events

Page 118: Session 303 - Staying on Track With Location Services

AutoPause API

• Enabled?@property BOOL pausesLocationUpdatesAutomatically

• Activity detection@property CLActivityType activityType

CLActivityTypeVehicularNavigationCLActivityTypeFitnessCLActivityTypeOther

• Handle pause events- locationManagerDidPauseLocationUpdates:

Page 119: Session 303 - Staying on Track With Location Services

AutoPause API

• Enabled?@property BOOL pausesLocationUpdatesAutomatically

• Activity detection@property CLActivityType activityType

CLActivityTypeVehicularNavigationCLActivityTypeFitnessCLActivityTypeOther

• Handle pause events- locationManagerDidPauseLocationUpdates:- locationManagerDidResumeLocationUpdates:

Page 120: Session 303 - Staying on Track With Location Services

Demo

Mike Dal SantoSoftware Engineer

Page 121: Session 303 - Staying on Track With Location Services

How to Respond

Page 122: Session 303 - Staying on Track With Location Services

• Take no action

How to Respond

Page 123: Session 303 - Staying on Track With Location Services

• Take no action• Notify the user

How to Respond

Page 124: Session 303 - Staying on Track With Location Services

• Take no action• Notify the user• Stop location updates

How to Respond

Page 125: Session 303 - Staying on Track With Location Services

Other Responses

Page 126: Session 303 - Staying on Track With Location Services

Other Responses

• Disable AutoPause

Page 127: Session 303 - Staying on Track With Location Services

Other Responses

• Disable AutoPauseself.manager.pausesLocationUpdatesAutomatically = NO;

Page 128: Session 303 - Staying on Track With Location Services

Other Responses

• Disable AutoPauseself.manager.pausesLocationUpdatesAutomatically = NO;

• Restart location

Page 129: Session 303 - Staying on Track With Location Services

Other Responses

• Disable AutoPauseself.manager.pausesLocationUpdatesAutomatically = NO;

• Restart location[self.manager startUpdatingLocation];

Page 130: Session 303 - Staying on Track With Location Services

Other Responses

• Disable AutoPauseself.manager.pausesLocationUpdatesAutomatically = NO;

• Restart location[self.manager startUpdatingLocation];

• Resume yourself

Page 131: Session 303 - Staying on Track With Location Services

Other Responses

• Disable AutoPauseself.manager.pausesLocationUpdatesAutomatically = NO;

• Restart location[self.manager startUpdatingLocation];

• Resume yourself[self.manager startMonitoringForRegion:currentLocation];

Page 132: Session 303 - Staying on Track With Location Services

Handling Location Updates

Page 133: Session 303 - Staying on Track With Location Services

Handling Location Updates

• New delegate method- (void)locationManager:(CLLocationManager *)manager

didUpdateLocations:(NSArray *)locations

Page 134: Session 303 - Staying on Track With Location Services

Handling Location Updates

• New delegate method- (void)locationManager:(CLLocationManager *)manager

didUpdateLocations:(NSArray *)locations

• Deprecated delegate method- (void)locationManager:(CLLocationManager *)manager! didUpdateToLocation:(CLLocation *)newLocation! ! fromLocation:(CLLocation *)oldLocation

Page 135: Session 303 - Staying on Track With Location Services

Help the user make an informed decisionAuthorization

Page 136: Session 303 - Staying on Track With Location Services

Help the user make an informed decisionAuthorization

Permission DialogShown once per application

Page 137: Session 303 - Staying on Track With Location Services

Help the user make an informed decisionAuthorization

Purpose propertyTell the user why your application needs to use location services

Page 138: Session 303 - Staying on Track With Location Services

Help the user make an informed decisionAuthorization

“Don’t Allow”Plan for it

Page 139: Session 303 - Staying on Track With Location Services

The user is in controlAuthorization

Page 140: Session 303 - Staying on Track With Location Services

The user is in controlAuthorization

Enabled switchRetrieve value from location manager class function

Page 141: Session 303 - Staying on Track With Location Services

The user is in controlAuthorization

List of applicationsApplications appear after requesting location services

Page 142: Session 303 - Staying on Track With Location Services

The user is in controlAuthorization

Location arrowDisplayed if the application has requested location within the last minute

Page 143: Session 303 - Staying on Track With Location Services

The user is in controlAuthorization

Location arrowDisplayed if the application is region monitoring

Page 144: Session 303 - Staying on Track With Location Services

The user is in controlAuthorization

Location arrowDisplayed if the application has requested location in the last 24 hours

Page 145: Session 303 - Staying on Track With Location Services

The user is in controlAuthorization

Approval switchCheck approval status using CLLocationManager

Page 146: Session 303 - Staying on Track With Location Services

The user is in controlAuthorization

Status bar iconVisible when an application is using the user’s location

Page 147: Session 303 - Staying on Track With Location Services

Getting User Permission

Page 148: Session 303 - Staying on Track With Location Services

Getting User Permission

Page 149: Session 303 - Staying on Track With Location Services

Getting User Permission

• Standardized usage descriptions in Info.plistNSLocationUsageDescription

Page 150: Session 303 - Staying on Track With Location Services

Getting User Permission

• Standardized usage descriptions in Info.plistNSLocationUsageDescription

• Deprecated existing API@property NSString *purpose

Page 151: Session 303 - Staying on Track With Location Services

Tips, Tricks, and Myths

Page 152: Session 303 - Staying on Track With Location Services

Myth: Maps Loads Location Faster

Page 153: Session 303 - Staying on Track With Location Services

Myth: Maps Loads Location Faster

Page 154: Session 303 - Staying on Track With Location Services

Myth: Maps Loads Location Faster

Page 155: Session 303 - Staying on Track With Location Services

Myth: Maps Loads Location Faster

Page 156: Session 303 - Staying on Track With Location Services

Myth: Maps Loads Location Faster

Page 157: Session 303 - Staying on Track With Location Services

Myth: Maps Loads Location Faster

Page 158: Session 303 - Staying on Track With Location Services

Myth: Maps Loads Location Faster

Page 159: Session 303 - Staying on Track With Location Services

Myth: Maps Loads Location Faster

Page 160: Session 303 - Staying on Track With Location Services

Myth: Maps Loads Location Faster

Page 161: Session 303 - Staying on Track With Location Services

Myth: Maps Loads Location Faster

Page 162: Session 303 - Staying on Track With Location Services

Myth: Maps Loads Location Faster

Page 163: Session 303 - Staying on Track With Location Services

Myth: Maps Loads Location Faster

Page 164: Session 303 - Staying on Track With Location Services

Myth: Turn Off Wi-Fi to Improve Accuracy

Page 165: Session 303 - Staying on Track With Location Services

Myth: Turn Off Wi-Fi to Improve Accuracy

Page 166: Session 303 - Staying on Track With Location Services

Myth: Turn Off Wi-Fi to Improve Accuracy

Page 167: Session 303 - Staying on Track With Location Services

Myth: Turn Off Wi-Fi to Improve Accuracy

Page 168: Session 303 - Staying on Track With Location Services

Myth: Turn Off Wi-Fi to Improve Accuracy

Page 169: Session 303 - Staying on Track With Location Services

Myth: Turn Off Wi-Fi to Improve Accuracy

Page 170: Session 303 - Staying on Track With Location Services
Page 171: Session 303 - Staying on Track With Location Services
Page 172: Session 303 - Staying on Track With Location Services
Page 173: Session 303 - Staying on Track With Location Services

Support an Offline User Experience

Page 174: Session 303 - Staying on Track With Location Services

Support an Offline User Experience

• Support poor coverage areas

Page 175: Session 303 - Staying on Track With Location Services

Support an Offline User Experience

• Support poor coverage areas• Minimize data

Page 176: Session 303 - Staying on Track With Location Services

Support an Offline User Experience

• Support poor coverage areas• Minimize data• Save user battery

Page 177: Session 303 - Staying on Track With Location Services

Support an Offline User Experience

• Support poor coverage areas• Minimize data• Save user battery• Improve app performance

Page 178: Session 303 - Staying on Track With Location Services

Support an Offline User Experience

• Support poor coverage areas• Minimize data• Save user battery• Improve app performance• Support iPod touches and Wi-Fi iPads

Page 179: Session 303 - Staying on Track With Location Services

Support an Offline User Experience

• Support poor coverage areas• Minimize data• Save user battery• Improve app performance• Support iPod touches and Wi-Fi iPads• Data Protection APIs

Page 180: Session 303 - Staying on Track With Location Services

Reasons to Run in the Background

Page 181: Session 303 - Staying on Track With Location Services

Reasons to Run in the Background

• Navigation

Page 182: Session 303 - Staying on Track With Location Services

Reasons to Run in the Background

• Navigation• Fitness

Page 183: Session 303 - Staying on Track With Location Services

Reasons to Run in the Background

• Navigation• Fitness• Reminders

Page 184: Session 303 - Staying on Track With Location Services

Reasons to Run in the Background

• Navigation• Fitness• Reminders• Automatic check-in

Page 185: Session 303 - Staying on Track With Location Services

Run All the Time

Page 186: Session 303 - Staying on Track With Location Services

Run All the Time

! <key>UIBackgroundModes</key>! <array>

! ! <string>location</string>! </array>

Page 187: Session 303 - Staying on Track With Location Services

Run All the Time

! <key>UIBackgroundModes</key>! <array>

! ! <string>location</string>! </array>! <key>Required background modes</key>! <array>! ! <string>App registers for location updates</string>! </array>

Page 188: Session 303 - Staying on Track With Location Services

Run All the Time

! <key>UIBackgroundModes</key>! <array>

! ! <string>location</string>! </array>! <key>Required background modes</key>! <array>! ! <string>App registers for location updates</string>! </array>

Page 189: Session 303 - Staying on Track With Location Services

Run When Necessary

Page 190: Session 303 - Staying on Track With Location Services

Run When Necessary

• Significant location changes

Page 191: Session 303 - Staying on Track With Location Services

Run When Necessary

• Significant location changes-startMonitoringSignificantLocationChanges

Page 192: Session 303 - Staying on Track With Location Services

Run When Necessary

• Significant location changes-startMonitoringSignificantLocationChanges-stopMonitoringSignificantLocationChanges

Page 193: Session 303 - Staying on Track With Location Services

Run When Necessary

• Significant location changes-startMonitoringSignificantLocationChanges-stopMonitoringSignificantLocationChanges-locationManager:didUpdateLocations:

Page 194: Session 303 - Staying on Track With Location Services

Run When Necessary

• Significant location changes-startMonitoringSignificantLocationChanges-stopMonitoringSignificantLocationChanges-locationManager:didUpdateLocations:

• Monitor specific regions

Page 195: Session 303 - Staying on Track With Location Services

Run When Necessary

• Significant location changes-startMonitoringSignificantLocationChanges-stopMonitoringSignificantLocationChanges-locationManager:didUpdateLocations:

• Monitor specific regions-startMonitoringForRegion:

Page 196: Session 303 - Staying on Track With Location Services

Run When Necessary

• Significant location changes-startMonitoringSignificantLocationChanges-stopMonitoringSignificantLocationChanges-locationManager:didUpdateLocations:

• Monitor specific regions-startMonitoringForRegion:-stopMonitoringForRegion:

Page 197: Session 303 - Staying on Track With Location Services

Run When Necessary

• Significant location changes-startMonitoringSignificantLocationChanges-stopMonitoringSignificantLocationChanges-locationManager:didUpdateLocations:

• Monitor specific regions-startMonitoringForRegion:-stopMonitoringForRegion:-locationManager:didEnterRegion:

Page 198: Session 303 - Staying on Track With Location Services

Run When Necessary

• Significant location changes-startMonitoringSignificantLocationChanges-stopMonitoringSignificantLocationChanges-locationManager:didUpdateLocations:

• Monitor specific regions-startMonitoringForRegion:-stopMonitoringForRegion:-locationManager:didEnterRegion:-locationManager:didExitRegion:

Page 199: Session 303 - Staying on Track With Location Services

Run When Necessary

• Significant location changes-startMonitoringSignificantLocationChanges-stopMonitoringSignificantLocationChanges-locationManager:didUpdateLocations:

• Monitor specific regions-startMonitoringForRegion:-stopMonitoringForRegion:-locationManager:didEnterRegion:-locationManager:didExitRegion:

• Run as long as you need to

Page 200: Session 303 - Staying on Track With Location Services

Run When Necessary

• Significant location changes-startMonitoringSignificantLocationChanges-stopMonitoringSignificantLocationChanges-locationManager:didUpdateLocations:

• Monitor specific regions-startMonitoringForRegion:-stopMonitoringForRegion:-locationManager:didEnterRegion:-locationManager:didExitRegion:

• Run as long as you need to-beginBackgroundTaskWithExpirationHandler:

Page 201: Session 303 - Staying on Track With Location Services

Start Responsibly

Page 202: Session 303 - Staying on Track With Location Services

Start Responsibly

- (void)startLocation{! UIApplication *app = [UIApplication sharedApplication];! self.bkgdTask = [app beginBackgroundTaskWithExpirationHandler:^{! ! [self stopLocation];! }];! [self startLocationTimer];! [self.locationManager startUpdatingLocations];! self.updatingLocations = YES;}

Page 203: Session 303 - Staying on Track With Location Services

Start Responsibly

- (void)startLocation{! UIApplication *app = [UIApplication sharedApplication];! self.bkgdTask = [app beginBackgroundTaskWithExpirationHandler:^{! ! [self stopLocation];! }];! [self startLocationTimer];! [self.locationManager startUpdatingLocations];! self.updatingLocations = YES;}

Page 204: Session 303 - Staying on Track With Location Services

Start Responsibly

- (void)startLocation{! UIApplication *app = [UIApplication sharedApplication];! self.bkgdTask = [app beginBackgroundTaskWithExpirationHandler:^{! ! [self stopLocation];! }];! [self startLocationTimer];! [self.locationManager startUpdatingLocations];! self.updatingLocations = YES;}

Page 205: Session 303 - Staying on Track With Location Services

Start Responsibly

- (void)startLocation{! UIApplication *app = [UIApplication sharedApplication];! self.bkgdTask = [app beginBackgroundTaskWithExpirationHandler:^{! ! [self stopLocation];! }];! [self startLocationTimer];! [self.locationManager startUpdatingLocations];! self.updatingLocations = YES;}

Page 206: Session 303 - Staying on Track With Location Services

Start Responsibly

- (void)startLocation{! UIApplication *app = [UIApplication sharedApplication];! self.bkgdTask = [app beginBackgroundTaskWithExpirationHandler:^{! ! [self stopLocation];! }];! [self startLocationTimer];! [self.locationManager startUpdatingLocations];! self.updatingLocations = YES;}

Page 207: Session 303 - Staying on Track With Location Services

Start Responsibly

- (void)startLocation{! UIApplication *app = [UIApplication sharedApplication];! self.bkgdTask = [app beginBackgroundTaskWithExpirationHandler:^{! ! [self stopLocation];! }];! [self startLocationTimer];! [self.locationManager startUpdatingLocations];! self.updatingLocations = YES;}

Page 208: Session 303 - Staying on Track With Location Services

Handling Updates

Page 209: Session 303 - Staying on Track With Location Services

Handling Updates

- (void)locationManager:(CLLocationManager *)manager! didUpdateLocations:(NSMutableArray *)newLocations {! if ([[newLocations lastObject] horizontalAccuracy] > self.userMinimum)! {! ! if (self.locationStarted) {! ! ! // wait for a better location! ! } else {! ! ! [self startLocation];! ! }! } else {! ! [self.view updateWithLocations:newLocations];! ! [self stopLocation];! }}

Page 210: Session 303 - Staying on Track With Location Services

Handling Updates

- (void)locationManager:(CLLocationManager *)manager! didUpdateLocations:(NSMutableArray *)newLocations {! if ([[newLocations lastObject] horizontalAccuracy] > self.userMinimum)! {! ! if (self.locationStarted) {! ! ! // wait for a better location! ! } else {! ! ! [self startLocation];! ! }! } else {! ! [self.view updateWithLocations:newLocations];! ! [self stopLocation];! }}

Page 211: Session 303 - Staying on Track With Location Services

Handling Updates

- (void)locationManager:(CLLocationManager *)manager! didUpdateLocations:(NSMutableArray *)newLocations {! if ([[newLocations lastObject] horizontalAccuracy] > self.userMinimum)! {! ! if (self.locationStarted) {! ! ! // wait for a better location! ! } else {! ! ! [self startLocation];! ! }! } else {! ! [self.view updateWithLocations:newLocations];! ! [self stopLocation];! }}

Page 212: Session 303 - Staying on Track With Location Services

Handling Updates

- (void)locationManager:(CLLocationManager *)manager! didUpdateLocations:(NSMutableArray *)newLocations {! if ([[newLocations lastObject] horizontalAccuracy] > self.userMinimum)! {! ! if (self.locationStarted) {! ! ! // wait for a better location! ! } else {! ! ! [self startLocation];! ! }! } else {! ! [self.view updateWithLocations:newLocations];! ! [self stopLocation];! }}

Page 213: Session 303 - Staying on Track With Location Services

Handling Updates

- (void)locationManager:(CLLocationManager *)manager! didUpdateLocations:(NSMutableArray *)newLocations {! if ([[newLocations lastObject] horizontalAccuracy] > self.userMinimum)! {! ! if (self.locationStarted) {! ! ! // wait for a better location! ! } else {! ! ! [self startLocation];! ! }! } else {! ! [self.view updateWithLocations:newLocations];! ! [self stopLocation];! }}

Page 214: Session 303 - Staying on Track With Location Services

Handling Updates

- (void)locationManager:(CLLocationManager *)manager! didUpdateLocations:(NSMutableArray *)newLocations {! if ([[newLocations lastObject] horizontalAccuracy] > self.userMinimum)! {! ! if (self.locationStarted) {! ! ! // wait for a better location! ! } else {! ! ! [self startLocation];! ! }! } else {! ! [self.view updateWithLocations:newLocations];! ! [self stopLocation];! }}

Page 215: Session 303 - Staying on Track With Location Services

Handling Updates

- (void)locationManager:(CLLocationManager *)manager! didUpdateLocations:(NSMutableArray *)newLocations {! if ([[newLocations lastObject] horizontalAccuracy] > self.userMinimum)! {! ! if (self.locationStarted) {! ! ! // wait for a better location! ! } else {! ! ! [self startLocation];! ! }! } else {! ! [self.view updateWithLocations:newLocations];! ! [self stopLocation];! }}

Page 216: Session 303 - Staying on Track With Location Services

Handling Updates

- (void)locationManager:(CLLocationManager *)manager! didUpdateLocations:(NSMutableArray *)newLocations {! if ([[newLocations lastObject] horizontalAccuracy] > self.userMinimum)! {! ! if (self.locationStarted) {! ! ! // wait for a better location! ! } else {! ! ! [self startLocation];! ! }! } else {! ! [self.view updateWithLocations:newLocations];! ! [self stopLocation];! }}

Page 217: Session 303 - Staying on Track With Location Services

Summary

Page 218: Session 303 - Staying on Track With Location Services

Summary

• Horizontal accuracy is better than ever

Page 219: Session 303 - Staying on Track With Location Services

Summary

• Horizontal accuracy is better than ever• Location is more available than ever

Page 220: Session 303 - Staying on Track With Location Services

Summary

• Horizontal accuracy is better than ever• Location is more available than ever• Power consumption is lower than ever

Page 221: Session 303 - Staying on Track With Location Services

Summary

Page 222: Session 303 - Staying on Track With Location Services

Summary

• Run only as needed

Page 223: Session 303 - Staying on Track With Location Services

Summary

• Run only as needed• Tell the user why

Page 224: Session 303 - Staying on Track With Location Services

Summary

• Run only as needed• Tell the user why • Specify your user’s activity

Page 225: Session 303 - Staying on Track With Location Services

Summary

• Run only as needed• Tell the user why • Specify your user’s activity• Leave Wi-Fi on

Page 226: Session 303 - Staying on Track With Location Services

More Information

Paul MarcosApp Services [email protected]

DocumentationLocation Awareness Programming Guidehttp://developer.apple.com/library/ios

Apple Developer Forumshttp://devforums.apple.com

Page 227: Session 303 - Staying on Track With Location Services

Related Sessions

Getting Around Using Map Kit Nob HillTuesday 9:00AM

Understanding Core Motion Pacific HeightsFriday 10:15AM

Page 228: Session 303 - Staying on Track With Location Services

Labs

Core Location Lab App Services Lab BWednesday 3:15PM

Core Motion Lab Graphics, Media & Games Lab DFriday 11:30AM

Page 229: Session 303 - Staying on Track With Location Services
Page 230: Session 303 - Staying on Track With Location Services

The last 3 slides after the logo are intentionally left blank for all presentations.

Page 231: Session 303 - Staying on Track With Location Services

The last 3 slides after the logo are intentionally left blank for all presentations.

Page 232: Session 303 - Staying on Track With Location Services

The last 3 slides after the logo are intentionally left blank for all presentations.