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 geofence takes the same NSDictionary structure as the response from creating, getting or updating one | |
| [[CCHGeofenceService sharedInstance] deleteGeofence:geofence completionHandler:^(NSError *error) { | |
| if (!error) { | |
| NSLog(@"Deleted geofence 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) { |
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
| // Set the data source and delegate to a class which will define the methods listed below | |
| // Typically this is the application delegate but it can be whatever makes sense in your application | |
| [[CCHSensorPipeline sharedInstance] setDataSource:self]; | |
| [[CCHSensorPipeline sharedInstance] setDelegate:self]; | |
| #pragma mark - Sensor Pipeline Data Source | |
| - (NSDictionary *)sensorPipeline:(CCHSensorPipeline *)sensorPipeline payloadForEvent:(NSDictionary *)event { | |
| // Add custom data structures to the events, and they will end up on the server. | |
| return @{}; |
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
| // Subscribe to "office-chaione" tag and start receiving events from beacon and geofence elements with that tag | |
| NSString *tag = @"office-chaione"; | |
| if ([[CCHSensorPipeline sharedInstance] addElementsWithTags:@[tag]]) { | |
| NSLog(@"Successfully added subscription to \"%@\" tag", tag); | |
| } else { | |
| NSLog(@"Failed to add subscription to \"%@\" tag", 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
| // Call method "handleEvent:" when an event will be posted | |
| // This method is called before a network request is made | |
| [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleEvent:) | |
| name:CCHSensorPipelineWillPostEvent object:nil]; | |
| // Call method "handleEvent:" when an event has been posted (recommended) | |
| // This method is made after a network request has been successful | |
| [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleEvent:) | |
| name:CCHSensorPipelineDidPostEvent object:nil]; | |
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
| - (void)handleEvent:(NSNotification *)notification { | |
| NSDictionary *event = notification.object; | |
| // Check if the event is a beacon event | |
| if ([event valueForKeyPath:CCHBeaconEventKeyPath]) { | |
| // Handle beacon event here | |
| // The "DetectMe" sample app goes into greater detail of handling beacon events | |
| } | |
| // Check if event is a geofence event |
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
| // Unsubscribe to "office-chaione" tag and stop receiving events from beacon and geofence elements with that tag | |
| NSString *tag = @"office-chaione"; | |
| if ([[CCHSensorPipeline sharedInstance] removeElementsWithTags:@[tag]]) { | |
| NSLog(@"Successfully removed subscription to \"%@\" tag", tag); | |
| } else { | |
| NSLog(@"Failed to remove subscription to \"%@\" tag", tag); | |
| } | |
| // Remove a specific observer from your class (recommended) | |
| [[NSNotificationCenter defaultCenter] removeObserver:self name:CCHSensorPipelineDidPostEvent object:nil]; |
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
| - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { | |
| #ifdef DEBUG | |
| // The debug flag is automatically set by the compiler, indicating which push gateway server your device will use | |
| // Xcode deployed builds use the sandbox/development server | |
| // TestFlight/App Store builds use the production server | |
| // ContextHub records which environment a device is using so push works properly | |
| // This must be called BEFORE [ContextHub registerWithAppId:] | |
| [[ContextHub sharedInstance] setDebug:TRUE]; | |
| #endif | |
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
| // Set up a push dictionary | |
| NSMutableDictionary *userInfo = [NSMutableDictionary dictionary]; | |
| // Add a message (optional for background pushes if push has sound key) | |
| userInfo[@"alert"] = @"alert"; | |
| // Add a sound (optional for background pushes if push has alert key) | |
| userInfo[@"sound"] = @"default"; | |
| // Add custom data (optional) |
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
| // Send a push to 2 devices with IDs defined below | |
| // Note: All device IDs are UUIDs, if a deviceID is not a valid UUID, then it is not a valid device ID | |
| // Note: userDict is the push dictionary, see above on how to set it up | |
| NSString *deviceID1 = @"20984403-690A-4098-8557-73B763F1DFFB"; | |
| NSString *deviceID2 = @"151E57AF-7E87-400F-A1E0-63C9E7811376"; | |
| [[CCHPush sharedInstance] sendNotificationToDevices:@[deviceID1, deviceID2] userInfo:userInfo completionHandler:^(NSError *error) { | |
| if (!error) { | |
| NSLog("Push to device ids \"%@, %@\" sent successfully", deviceID1, deviceID2); | |
| } else { |
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
| // Send a push notification to 2 devices, with aliases "Michael's iPhone 5s" and "Jeff's iPhone 5" | |
| // Note: userDict is the push dictionary, see above on how to set it up | |
| NSString *alias1 = @"Michael's iPhone 5s"; | |
| NSString *alias2 = @"Jeff's iPhone 5"; | |
| [[CCHPush sharedInstance] sendNotificationToAliases:@[alias1, alias2] userInfo:userInfo completionHandler:^(NSError *error) { | |
| if (!error) { | |
| NSLog("Push to aliases \"%@, %@\" sent successfully", alias1, alias2); | |
| } else { | |
| NSLog("Push to aliases \"%@, %@\" failed", alias1, alias2); |