Skip to content

Instantly share code, notes, and snippets.

@CHLibrarian
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CHLibrarian/8b4d81f756ef8588629c to your computer and use it in GitHub Desktop.
Save CHLibrarian/8b4d81f756ef8588629c to your computer and use it in GitHub Desktop.
ContextHub Application Services Register Push Gist
- (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
// Register the app id of the application you created on https://app.contexthub.com
[ContextHub registerWithAppId:@"YOUR-APP-ID-HERE"];
// Register for remote notifications
#ifdef __IPHONE_8_0
// iOS 8 and above
UIUserNotificationType notificationTypes = UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound;
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:notificationTypes categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
#else
// iOS 7 and below
UIRemoteNotificationType notificationTypes = UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound;
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:notificationTypes];
#endif
return YES;
}
#ifdef __IPHONE_8_0
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
{
// Register to receive notifications
[application registerForRemoteNotifications];
}
- (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forRemoteNotification:(NSDictionary *)userInfo completionHandler:(void(^)())completionHandler
{
// Handle the actions
if ([identifier isEqualToString:@"declineAction"]){
} else if ([identifier isEqualToString:@"answerAction"]){
}
}
#endif
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
NSString *alias = @"alias";
NSArray *tags = @[@"tag1", @"tag2"];
[[CCHPush sharedInstance] registerDeviceToken:deviceToken alias:alias tags:tags completionHandler:^(NSError *error) {
if (!error) {
NSLog(@"Successfully registered device with alias %@ and tags %@", alias, @"tag1, tag2");
}
else {
NSLog(@"Error: %@", error);
}
}];
}
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
NSLog(@"Did fail to register %@", error);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment