Skip to content

Instantly share code, notes, and snippets.

@CHLibrarian
Created August 11, 2014 20:41
Show Gist options
  • Save CHLibrarian/81a90f9f2c08c4f35cf2 to your computer and use it in GitHub Desktop.
Save CHLibrarian/81a90f9f2c08c4f35cf2 to your computer and use it in GitHub Desktop.
ContextHub Element Services Geofence Update Gist
// Updating a geofence with the name "Geofence 2" and adding the tag "office"
// In order to update a geofence, you need to pass in a dictionary with the same dictionary structure as from either the create or get methods
// Note, this is where a custom class is very helpful in taking the information in a CLCircularRegion (which is marked partly read-only by Apple) and updating it
// See GFGeofence in Geofences sample app for more information
NSString *name = @"Geofence 2";
CLLocationDegrees lat = 29.742964f;
CLLocationDegrees lng = -95.353605f;
CLLLocationDistance radius = 250.0f; // in meters
NSString *geofenceTag = @"geofence-tag";
NSString *geofenceTag2 = @"office";
NSString *latString = [NSString stringWithFormat: @"%.6f", lat];
NSString *lngString = [NSString stringWithFormat: @"%.6f", lng];
NSString *radString = [NSString stringWithFormat: @"%.6f", radius];
NSNumber *geofenceID = @1000;
NSDictionary *geofenceDict = @{ @"id":geofenceID, @"name":name, @"latitude":latString, @"longitude":lngString, @"radius":radString, @"tags":@[geofenceTag, geofenceTag2] };
[[CCHGeofenceService sharedInstance] updateGeofence:geofenceDict completionHandler:^(NSError *error) {
if (!error) {
NSLog(@"Updated geofence in ContextHub");
// If you do not have push properly set up, you need to explicitly call synchronize on CCHSensorPipeline so it will start/stop 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");
}
}];
} else {
NSLog(@"Could not update geofence in ContextHub");
}
}];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment