nor0x
nor0x

Reputation: 1212

Azure App Service - Send push notification to specific users

I am using Azure App Service (Node.js) in combination with Notification Hubs to register for push notifications from an iOS app. Since tags are not available anymore in App Service with a Node.js backend, how can I target specific users for the push notification.

Once the user is authenticated (i.e. via Facebook) in the iOS app a userId tag gets added automatically to the registration. When I was using Mobile Services I could use the following code to add tags to the device registration in the Notification Hub:

-(void)registerDeviceToken:(nonnull NSData *)deviceToken completion:(nullable MSCompletionBlock)completion;

But the new SDK doesn't provide a method which allows registration with tags:

- (void)registerNativeWithDeviceToken:(NSData*)deviceToken tags:(NSSet*)tags completion:(void (^)(NSError* error))completion;

My problem is that the format of the userId is not like Facebook:123456789 (as is was with Mobile Services), instead a GUID is generated automatically during the registration process - which I can't store and query it later when sending out the notification.

Can anybody help me how I can use Azure App Service with Notification Hubs and Node.js to send notifications to specific users?

Upvotes: 0

Views: 1181

Answers (1)

Gary Liu
Gary Liu

Reputation: 13918

There is a similar thread on MSDN at https://social.msdn.microsoft.com/Forums/azure/en-US/ed5327f6-6f0a-4cbc-91d4-74a9885e2131/nodejs-after-i-upgraded-my-ios-app-from-mobile-services-to-app-services-i-cant-register-for?forum=azuremobile for you information.

Per the answers, we know that

The default registration code does not allow you to register for tags deliberately

And we can get the hint from How to: Add tags to a device installation to enable push-to-tags in .Net:

Following the above How to: Define a custom API controller, you will want to set up a custom API on your backend to work with Notification Hubs to add tags to a specific device installation. Make sure you pass along the Installation ID stored on the client local storage and the tags you want to add (optional, since you can also specify tags directly on your backend). The following snippet should be added to your controller to work with Notification Hubs to add a tag to a device Installation ID.

And in Node.js backend, we can leverage Azure SDK for Node.js which contains the functions to push notifications, we can see the usage at https://github.com/Azure/azure-sdk-for-node/blob/master/examples/notification-hubs.md.

Additionally, we can get the detailed reference of send() function from the source code repository at https://github.com/Azure/azure-sdk-for-node/blob/master/lib/services/serviceBus/lib/notificationhubservice.js#L116

Upvotes: 0

Related Questions