Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Geofencing in iOS

Geofencing in iOS

Slides from a talk exploring Core Location in iOS through the lense of an app that uses region monitoring (geofencing). Code is at http://git.io/oqlCHQ

Kevin McMahon

May 19, 2012
Tweet

More Decks by Kevin McMahon

Other Decks in Programming

Transcript

  1. @property CLLocationAccuracy desiredAccuracy; @property CLLocationDistance distanceFilter; - (void)startUpdatingLocation; - (void)stopUpdatingLocation;

    - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation; Saturday, May 19, 12
  2. typedef { CLLocationDegrees latitude; // a double CLLocationDegrees longitude; //

    a double } CLLocationCoordinate2D; @properties CLLocationCoordinate2D coordinate; @property (readonly) CLLocationDistance altitude; @property (readonly) CLLocationAccuracy horizontalAccuracy; @property (readonly) CLLocationAccuracy verticalAccuracy; @property (readonly) CLLocationSpeed speed; // in meters/second @property (readonly) CLLocationDirection course; @property (readonly) NSDate *timestamp; - (CLLocationDistance)distanceFromLocation:(CLLocation *)otherLocation; Saturday, May 19, 12
  3. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { id location = [launchOptions

    valueForKey:UIApplicationLaunchOptionsLocationKey]; if(location) { // React to the location update } } Saturday, May 19, 12
  4. @property (readonly) NSSet *monitoredRegions; - (void)startMonitoringForRegion:(CLRegion *); - (void)startMonitoringForRegion:(CLRegion *)

    desiredAccuracy:(CLLocationAccuracy); - (void)stopMonitoringForRegion:(CLRegion *); // Delegate Methods - (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region; - (void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region; - (void)locationManager:(CLLocationManager *)manager monitoringDidFailForRegion:(CLRegion *)region withError:(NSError *)error; Saturday, May 19, 12
  5. typedef enum { kCLErrorLocationUnknown = 0, kCLErrorDenied, kCLErrorNetwork, kCLErrorHeadingFailure, kCLErrorRegionMonitoringDenied,

    kCLErrorRegionMonitoringFailure, kCLErrorRegionMonitoringSetupDelayed } CLError; Saturday, May 19, 12