I've created an iphone app with push notification using Azure notification hub. But I'm having a hard time getting the push to work.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
/******** code for Push notification **********/
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
[[UIApplication sharedApplication] registerForRemoteNotifications];
NSLog(@"Entered appDelegate didFinishLaunchingWithOptions");
return YES;
}
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *) deviceToken {
SBNotificationHub* hub = [[SBNotificationHub alloc] initWithConnectionString:@"<my azure listening connection string>" notificationHubPath:@"myhub"];
NSLog(@" DeviceToken: %@",deviceToken);
[hub registerNativeWithDeviceToken:deviceToken tags:nil completion:^(NSError* error) {
if (error != nil) {
NSLog(@"Error registering for notifications: %@", error);
}
else {
[self MessageBox:@"Registration Status" message:@"Registered"];
}
}];
}
-(void)MessageBox:(NSString *)title message:(NSString *)messageText {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title message:messageText delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
[alert show];
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification: (NSDictionary *)userInfo {
NSLog(@"%@", userInfo);
[self MessageBox:@"Notification" message:[[userInfo objectForKey:@"aps"] valueForKey:@"alert"]];
}
I've followed the steps form this document:
https://azure.microsoft.com/en-us/documentation/articles/notification-hubs-ios-get-started/
I've created an explicit app id on the Member center and it matches my bundle id. I'm using developer cert and chose "sandbox" under Azure.
When I first launched my app on to my iphone (not simulator) I get the prompt to accept push notifications - I chose yes. Then my code gets a token from apple and registers that with Azure NH, which is successful.
From Azure NH debug tab, I did a broadcast send which was successfully sent from Azure to APNS. But I never received any notifications. Here is the body of the push notification message on Azure:
{"aps":{"alert":"Notification Hub test notification"}}
I have tried this multiple times and even created an isolated project just to test push notification (separate certs, provisioning profile etc) and it still does not work.
When I intentionally malform the payload of the message for Push, I do get an error as expected So it seems that the connection from NH to APNS is good.
My requirement is to send around 100 million pushes a month.
If anyone has used Azure notification for push notifications then please advice how to fix this?
If anyone has had poor experience with Azure NH then please share what you ended up migrating to.
Thanks in advance.
I was able to get this to work.
I deleted all certificates on Apple developer center and my mac. I recreated the certificates and then followed the process again. It all worked out this time.
Thanks.