Reputation: 684
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:
Is it correct? Does anybody knows about examples or documentation for the back-end registration management?
Upvotes: 1
Views: 5277
Reputation: 860
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.
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:
We will add a sample for this scenario asap.
Upvotes: 2