Skip to content

Instantly share code, notes, and snippets.

@CHLibrarian
Last active August 29, 2015 14:04
Show Gist options
  • Save CHLibrarian/604928d3705c3d0d78cd to your computer and use it in GitHub Desktop.
Save CHLibrarian/604928d3705c3d0d78cd to your computer and use it in GitHub Desktop.
ContextHub Element Services Geofence Create Gist
// Creating a geofence with name "Geofence", tag "geofence-tag", radius 250 meters
NSString *name = @"Geofence";
CLLocationDegrees lat = 29.763638f;
CLLocationDegrees lng = -95.461874f;
CLLocationCoordinate2D center = CLLocationCoordinate2DMake(lat, lng);
CLLLocationDistance radius = 250.0f; // in meters
NSString *geofenceTag = @"geofence-tag";
[[CCHGeofenceService sharedInstance] createGeofenceWithCenter:center radius:radius tags:@[geofenceTag] competionHandler:^(NSDictionary *geofence, NSError *error) {
if (!error) {
// Standard CLCircularRegion class
CLCircularRegion *createdGeofence = [CCHGeofenceService regionForGeofence:geofence];
// If you do not have push properly set up, you need to explicitly call synchronize on CCHSensorPipeline so it will generate events if it applies to this device
[[CCHSensorPipeline sharedInstance] synchronize:^(NSError *error) {
if (!error) {
NSLog(@"Successfully synchronized with ContextHub");
} else {
NSLog(@"Could not synchronize withContextHub");
}
}];
// The geofence dictionary also contains useful information like the id and tags of the geofences stored in ContextHub
// It is recommended you make a custom class that wraps that information to make it easier to access
// The Geofence sample app creates the GFGeofence class and can act as a model for your own classes
} else {
NSLog(@"Could not create geofence %@ on ContextHub", name);
}
}];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment