Skip to content

Instantly share code, notes, and snippets.

View CHLibrarian's full-sized avatar

ContextHub CHLibrarian

View GitHub Profile
@CHLibrarian
CHLibrarian / application-services-device-setting-ios.mm
Created December 4, 2014 21:10
Application Services Device Setting (iOS)
NSString *updatedAlias = @"john@example.com";
NSString *updatedTag1 = @"Austin";
NSString *updatedTag2 = @"Field Rep";
// Update device with new alias and tags
[[CCHDevice sharedInstance] setAlias:updatedAlias tags:@[updatedTag1, updatedTag2] completionHandler:^(NSDictionary *device, NSError *error)completionHandler {
if (!error) {
NSLog(@"Device alias/tag updated");
} else {
NSLog(@"Failed to set new alias/tag for device in ContextHub");
}
@CHLibrarian
CHLibrarian / application-services-device-retrieve-by-tag-ios.mm
Last active August 29, 2015 14:10
Application Services Device Retrieve by Tag iOS)
NSString *deviceTag1 = @"Houston";
NSString *deviceTag2 = @"Engineer";
// Retrieve all devices that have the tag "Houston" and "Engineer"
[[CCHDevice sharedInstance] getDevicesWithTags:@[deviceTag1, deviceTag2] completionHandler:^(NSArray *devices, NSError *error)completionHandler {
if (!error) {
// Access individual devices here
NSArray *retrievedDevices = devices;
} else {
NSLog(@"Error retrieving devices by tags from ContextHub");
}
@CHLibrarian
CHLibrarian / application-services-device-retrieve-by-alias-ios.mm
Last active August 29, 2015 14:10
Application Services Device Retrieve by Alias iOS)
NSString *deviceAlias = @"jim@example.com";
// Retrieve devices with alias "jim@example.com"
[[CCHDevice sharedInstance] getDevicesWithAlias:deviceAlias completionHandler:^(NSArray *devices, NSError *error)completionHandler {
if (!error) {
// Access individual devices here
NSArray *retrievedDevices = devices;
} else {
NSLog(@"Error retrieving devices by alias from ContextHub");
}
}];
@CHLibrarian
CHLibrarian / application-service-device-retrieve-by-id-ios.mm
Last active August 29, 2015 14:10
Application Services Device Retrieve by ID (iOS)
NSString *deviceToRetrieveID = @"76BC4719-6344-4E62-8FA2-F00A8D29B60E";
// Retrieve device from ContextHub
[[CCHDevice sharedInstance] getDeviceWithId:deviceToRetrieveID completionHandler:^(NSDictionary *device, NSError *error)completionHandler {
if (!error) {
NSString *deviceID = device[@"id"];
NSString *deviceType = device[@"device_type"];
// Not present if not previously set
NSString *deviceAlias = device[@"alias"];
NSArray *deviceTags = device[@"tags"];
@CHLibrarian
CHLibrarian / application-services-device-id-ios.mm
Created December 4, 2014 20:08
Application Services Device ID (iOS)
// Retrieve device ID (in standard 8-4-4-4-12 UUID format, ex: 76BC4719-6344-4E62-8FA2-F00A8D29B60E)
NSString *deviceID = [CCHDevice deviceID];
@CHLibrarian
CHLibrarian / application-service-logging-ios.mm
Last active August 29, 2015 14:10
Application Services Logging
NSString *logMessage = @"Logging message";
NSDictionary *logDictionary = @{@"key1": @"value1", @"key2": @"value2"};
// Logging a message and a custom valid-JSON dictionary to ContextHub
[[CCHLog sharedInstance] log:logMessage userInfo:logDictionary completionHandler:(void (^)(NSError *error))completionHandler {
if (!error) {
NSLog(@"Message logged successfully");
} else {
NSLog(@"Failed to log message to Contexthub");
}
}];
@CHLibrarian
CHLibrarian / application-services-register-app-android.java
Created December 2, 2014 22:35
ContextHub Application Services Register App (Android)
public class MyContextHubApp extends Application {
@Override
public void onCreate() {
super.onCreate();
// Register with ContextHub
ContextHub.init(this, "YOUR-APP-ID-HERE");
}
}
@CHLibrarian
CHLibrarian / event-services-listener-android.java
Created November 24, 2014 20:35
ContextHub Event Services Listener (Android)
@Override
public void onResume() {
super.onResume();
// start listening to events
ContextHub.getInstance().addSensorPipelineListener(this);
}
@Override
public void onPause() {
@CHLibrarian
CHLibrarian / element-services-subscription-remove-android.java
Created November 24, 2014 20:06
ContextHub Element Services Subscription Remove (Android)
// Unsubscribing from tag "my-tag-2"
// We want to unsubscribe from tag "my-tag-2", so we specify the REMOVE operation and the tag to remove.
SubscriptionProxy proxy = new SubscriptionProxy();
List<String> tagList = Arrays.asList("my-tag-2");
List<String> subscriptionTypes = Arrays.asList("beacon", "geofence", "vault");
proxy.updateSubscriptions(SubscriptionOperation.REMOVE, tagList, subscriptionTypes, new Callback<SubscriptionResponse>() {
@Override
public void onSuccess(SubscriptionResponse result) {
Toast.makeText(getActivity(), ("Beacon, geofence, and vault subscriptions removed", Toast.LENGTH_SHORT).show();
}
@CHLibrarian
CHLibrarian / element-services-subscription-retrieve-android.java
Created November 24, 2014 19:46
ContextHub Element Services Subscription Retrieve (Android)
// Getting tag subscriptions
SubscriptionProxy proxy = new SubscriptionProxy();
proxy.listSubscriptions(new Callback<SubscriptionResponse>() {
@Override
public void onSuccess(SubscriptionResponse result) {
Log.d(TAG, result.getBeaconSubscription().toString());
Log.d(TAG, result.getGeofenceSubscription().toString());
Log.d(TAG, result.getVaultSubscription().toString());
}