Last active
August 29, 2015 14:04
-
-
Save CHLibrarian/9a88528f3c94bc524a47 to your computer and use it in GitHub Desktop.
ContextHub Element Services Beacon Create Gist
This file contains 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) { | |
// Standard CLBeaconRegion class | |
CLBeaconRegion *createdBeacon = [CCHBeaconService regionForBeacon:beacon]; | |
// 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(@"DM: Successfully synchronized with ContextHub"); | |
} else { | |
NSLog(@"DM: Could not synchronize withContextHub"); | |
} | |
}]; | |
// The beacon dictionary also contains useful information like the id and tags of the beacon stored in ContextHub | |
// It is recommended you make a custom class that wraps that information to make it easier to access | |
// The DetectMe sample app creates the DMBeacon class and can act as a model for your own classes | |
} else { | |
NSLog(@"Could not create beacon %@ on ContextHub", name); | |
} | |
}]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment