Question

I'm trying to use Azure Notification Hub for push notifications. According to the MSDN article there are two ways for registration management. In tutorials it's explained the first approach - registration management in client applications. However, it looks more appropriate for my needs the second approach - registration management in the app back-end.

I can't find any documentation or examples how to do it. Specifically I'm interested in integration with iOS mobile applications.
As far as I understand the registration flow suppose to be like this:

  1. Native application sends HTTP request passing device id and application name to the back-end during the start.
  2. Back-end suppose to register the device in Notification Hub (I guess using CreateAppleTemplateRegistration for template notification)
  3. As soon as registration is expired back-end is responsible to update the registration

Is it correct? Does anybody knows about examples or documentation for the back-end registration management?

Was it helpful?

Solution

Update

The scenario is now fully explained in : http://www.windowsazure.com/en-us/manage/services/notification-hubs/notify-users-aspnet/

The solution below does not work anymore as Notification Hubs is out of preview and there were some breaking changes in the .NET SDK.

Old answer

The solution you outlined is correct. The caveat is that when doing registration mgmt from the app back-end you have to store the token currently registered somewhere (usually in the device app, but in an installation table in the back-end works too).

Assuming you are storing the 'old' token on the device, you have to implement the following logic.

In the back-end

An endpoint that takes two parameters: 'oldToken', 'newToken'. This basically, either creates a new registration (change template/native or tags as needed), or updates the current one.

var hubClient = NotificationHubClient.CreateClientFromConnectionString(connectionString, "<notification hub name>");
if (hubClient.RegistrationExists("oldDeviceToken"))
{
    hubClient.UpdateRegistrationsWithNewPnsHandle("oldDeviceToken", "newDeviceToken");
} else
{
    hubClient.CreateAppleNativeRegistration("newDeviceToken", new string[] {"myTag"});
}

More scenarios are possible where you modify current registrations, add tags, modify templates... On hubClient you have all those methods and they are self explanatory. Some high level info is at the end of this article.

In the device app

Implement the following logic:

  • If there is no old token stored, contact the back-end with the new token (backendEndpoint(newToken, newToken)), when it returns store the token locally
  • If there is an old token, and it different than the new one, contact the back-end with old and new token (backendEndpoint(oldToken, newToken)), when the calls completes store the new token locally.
  • If there is an old token and it is no different than the new one, but the last registration happened more than 30 days ago, call the back-end with the old token (backendEndpoint(oldToken, oldToken)).

We will add a sample for this scenario asap.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top