Skip to content

Instantly share code, notes, and snippets.

View CHLibrarian's full-sized avatar

ContextHub CHLibrarian

View GitHub Profile
@CHLibrarian
CHLibrarian / element-services-beacon-create.mm
Last active August 29, 2015 14:04
ContextHub Element Services Beacon Create Gist
// 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) {
@CHLibrarian
CHLibrarian / element-services-geofences-create.mm
Last active August 29, 2015 14:04
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) {
@CHLibrarian
CHLibrarian / element-services-subscription-add.mm
Last active August 29, 2015 14:04
ContextHub Element Services Subscription Add Gist
// 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);
}
@CHLibrarian
CHLibrarian / element-services-beacon-retrieve-tags.mm
Created August 11, 2014 19:49
ContextHub Element Services Beacon Retrieve Tags Gist
// Getting all beacons with the tag "beacon-tag"
NSString *beaconTag = @"beacon-tag";
[[CCHBeaconService sharedInstance] getBeaconsWithTags:@[beaconTag] completionHandler:^(NSArray *beacons, NSError *error) {
if (!error) {
for (NSDictionary *beaconDict in beacons) {
CLBeaconRegion *beaconRegion = [CCHBeaconService regionForBeacon:beaconDict];
}
} else {
NSLog(@"Could not get beacons from ContextHub");
@CHLibrarian
CHLibrarian / element-services-beacon-retrieve-id.mm
Created August 11, 2014 19:52
ContextHub Element Services Beacon Retrieve ID Gist
// 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");
}
}];
@CHLibrarian
CHLibrarian / element-services-beacon-update.mm
Last active August 29, 2015 14:05
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";
@CHLibrarian
CHLibrarian / element-services-beacon-delete.mm
Last active August 29, 2015 14:05
ContextHub Element Services Beacon Delete Gist
// 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) {
@CHLibrarian
CHLibrarian / element-services-geofence-retrieve-tags.mm
Created August 11, 2014 20:29
ContextHub Element Services Geofence Retrieve Tags Gist
// Getting all geofences with the tag "geofence-tag" near our location in 2000 meter radius
// currentLocation is our current location from CLLLocationManager
NSString *geofenceTag = @"geofence-tag";
[[CCHGeofenceService sharedInstance] getGeofencesWithTags:@[geofenceTag] location:currentLocation radius:2000 completionHandler:^(NSArray *geofences, NSError *error) {
if (!error) {
for (NSDictionary *geofenceDict in geofences) {
CLCircularRegion *geofenceRegion = [CCHGeofenceService regionForGeofence:geofenceDict];
}
} else {
@CHLibrarian
CHLibrarian / element-services-geofence-retreive-id.mm
Created August 11, 2014 20:39
ContextHub Element Services Geofence Retrieve ID Gist
// 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");
}
}];
@CHLibrarian
CHLibrarian / element-services-geofence-update.mm
Created August 11, 2014 20:41
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";