Skip to content

Instantly share code, notes, and snippets.

@CHLibrarian
Last active August 29, 2015 14:05
Show Gist options
  • Save CHLibrarian/d9bc6b5675b062b11dbf to your computer and use it in GitHub Desktop.
Save CHLibrarian/d9bc6b5675b062b11dbf to your computer and use it in GitHub Desktop.
ContextHub Element Services Beacon Update Gist
// Updating a beacon with the name "Beacon 2" and adding the tag "park"
// In order to update a beacon, 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 CLBeaconRegion (which is marked partly read-only by Apple) and updating it
// See DMBeacon in DetectMe sample app for more information
NSString *name = @"Beacon 2";
NSString *uuidString = @"B9407F30-F5F8-466E-AFF9-25556B57FE6D";
CLBeaconMajorValue major = 100;
CLBeaconMinorValue minor = 1;
NSString *beaconTag = @"beacon-tag";
NSString *beaconTag2 = @"park";
NSNumber *beaconID = @1000;
NSDictionary *beaconDict = @{ @"id":beaconID, @"major": major, @"minor":minor, @"uuid": uuidString, @"tags":@[beaconTag, beaconTag2] };
[[CCHBeaconService sharedInstance] updateBeacon:beaconDict completionHandler:^(NSError *error) {
if (!error) {
NSLog(@"Updated beacon 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 with ContextHub");
}
}];
} else {
NSLog(@"Could not update beacon in ContextHub");
}
}];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment