1
votes

I have to send push notifications to the specific users from the azure database list on insert of column into table. I am not sure which way I should I use direct APNS or Notifications hub?

1) If i use direct APNS from azure(below insert query), on insert of column in table TODOITEM I gets the push notification , but What should i do to send it to specific user from table I figured out null should be replaced with tokens where do I get specific user tokes

 function insert(item, user, request) {
request.execute();

setTimeout(function() {
    push.apns.send(null, {
        alert: "Alert: " + item.text,
        payload: {
            inAppMessage: "Hey, a new item arrived: '" + item.text + "'"
        }
    });
}, 2500);}

2) If i use the notification hub, I am not even able to use the push notification on insert of column in table which was happening in first case. in IOS side, I am using code for notification hub:

SBNotificationHub* hub = [[SBNotificationHub alloc] initWithConnectionString:
                          @"..
[hub registerNativeWithDeviceToken:deviceToken tags:nil completion:^(NSError* error) {
    if (error != nil) {
        NSLog(@"Error registering for notifications: %@", error);
    }
}];

How do I send the notification on table insert as it was happening in case 1 and how do i send to specific user of table (is there any way i can query the table and send)

Please can you answer both the cases.

1

1 Answers

0
votes

You need to use tags. A tag can uniquely identify a device (unique ID) or a group of devices (ex: country, team, etc).

In your iOS code, your currently passing a nil to the tags parameter. Change that to a unique ID but don't use the device token. I just lost an entire day figuring out that it's too long but doesn't generate any errors if used as a tag. Go figure! I'm using a GUID that I generate each time the app is launched and I store it on the backend.

In your JS code, replace null with the unique ID. You can specify multiple tags using a string (not an array) separating the tags with commas and no spaces.

In the portal, you can open the Service Hub page and use the debug tab to send a test notification using a tag.