This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Creating a beacon region with name "Beacon", tag "beacon-tag" | |
NSString *name = @"Beacon"; | |
NSString *uuidString = @"B9407F30-F5F8-466E-AFF9-25556B57FE6D"; | |
NSUUID *uuid = [[NSUUID alloc] initWithUUIDString:uuidString]; | |
CLBeaconMajorValue major = 100; | |
CLBeaconMinorValue minor = 1; | |
NSString *beaconTag = @"beacon-tag"; | |
[[CCHBeaconService sharedInstance] createBeaconWithProximityUUID:uuid major:major minor:minor tags:@[beaconTag] completionHandler:^(NSDictionary *beacon, NSError *error) { | |
if (!error) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Subscribing to a tag | |
// We want to subscribe to tag "beacon-tag" to be notified when a beacon with that tag is created, updated, or deleted | |
NSString *tag = @"beacon-tag"; | |
[[CCHSubscriptionService sharedInstance] addSubscriptionForTags:@[tag] options:@[CCHOptionBeacon] completionHandler:^(NSError *error) { | |
if (!error) { | |
NSLog(@"Subscribed to tag %@ in ContextHub, tag"); | |
} else { | |
NSLog(@"Could not subscribe to tag %@ ContextHub", tag); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Getting a beacon with a specific ID | |
NSString *beaconID = @"1000"; | |
[[CCHBeaconService sharedInstance] getBeaconWithId:beaconID completionHandler:^(NSDictionary *beacon, NSError *error)completionHandler { | |
if (!error) { | |
CLBeaconRegion *beaconRegion = [CCHBeaconService regionForBeacon:beacon]; | |
} else { | |
NSLog(@"Could not get beacon from ContextHub"); | |
} | |
}]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Deleting a beacon takes the same NSDictionary structure as updating one | |
[[CCHBeaconService sharedInstance] deleteBeacon:beaconDict completionHandler:^(NSError *error) { | |
if (!error) { | |
NSLog(@"Deleted beacon in ContextHub"); | |
// If you do not have push properly set up, you need to explicitly call synchronize on CCHSensorPipeline so it will stop generate events if it applies to this device | |
[[CCHSensorPipeline sharedInstance] synchronize:^(NSError *error) { | |
if (!error) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Getting a geofence with a specific ID | |
NSString *geofenceID = @"1000"; | |
[[CCHGeofenceService sharedInstance] getGeofenceWithId:geofenceID completionHandler:^(NSDictionary *geofence, NSError *error)completionHandler { | |
if (!error) { | |
CLCircularRegion *geofenceRegion = [CCHGeofenceService regionForGeofence:geofence]; | |
} else { | |
NSLog(@"Could not get geofence from ContextHub"); | |
} | |
}]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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"; |
OlderNewer