Advertisement
headsortail

iOS Registering for Azure Notification Hub Template Msg

Oct 8th, 2013
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
  2.  
  3.     //create the template
  4.     NSString *templateName = @"alertTemplate";
  5.     NSString *template = @"{\"aps\": {\"alert\": \"$(alert)\"}}";
  6.    
  7.     //create my specific tags that I want to receive
  8.     NSMutableSet *setTags = [NSMutableSet set];
  9.     [setTags addObject:[NSString stringWithFormat:@"user_id:%lld", userId]];
  10.    
  11.     //register this device
  12.     hub = [[SBNotificationHub alloc] initWithConnectionString:azureNotificationHubListen notificationHubPath:azureNotificationHubPath];
  13.     [hub registerTemplateWithDeviceToken:deviceToken name:templateName jsonBodyTemplate:template expiryTemplate:@"0" tags:setTags completion:^(NSError *error) {
  14.         if (error) {
  15.             NSLog(@"Error registering for notifications with Azure: %@", [error localizedDescription]);
  16.         } else {
  17.             NSLog(@"Registered to receive notifications with tag: %@", [setTags allObjects]);
  18.         }
  19.     }];
  20.  
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement