I've created a sample App with Cordova and a Mvc5 application that talks with Azure Notification Hubs.
Registrations are handled by the backend because tags must be secured.
We have used three different templates registered from the backend for the iOS,WP8 and Android platforms; the backend can send a push notification with a $message
payload using sendtemplatenotificationasync
.
It's working but we have not used the templateName
.
Reading the Registration from your app Backend documentation , I've found this:
"You can identify the templates by using the TemplateName property of
the registration".
Once I have successfully created a Registration with a templateName what can I do with it?
I expected to find an API Send method to be able to specify, besides the tags or tag expression, a specific templateName
; I have not found anything like this.
What's the meaning and the general use case of templateName
?
The template name is just a descriptive label for the template registration. It is not intended to be used to programmatically identify registrations and therefore there aren't any API methods that use the template name. You shouldn't use it for anything other than debugging or logging. (I don't set template names at all...)
You can check the official ANH Java SDK on GitHub for example: If you search for "templatename", you won't find any usage other than setting the template name for a registration.
All your templates should use the same template parameters, if they are intended for the same notification type. Then you just send a template notification with all the parameters to all platforms at once. That is the use case for template registrations. As far as I know, you can have additional parameters for specific platforms, registrations that don't specify a parameter, just won't receive it. Just make sure you send all parameters that are defined in all templates.
If you wan't to distinguish between registrations with different templates, use tags, e.g. for distinguishing platforms use tags like "Platform:Android", "Platform:iOS", etc. Or for distinguishing templates with different parameters use "Template:PersonalMessage", "Template:GroupMessage", "Template:BroadCast", etc...
Let's say you have iOS and Android clients. For iOS you would register with template that is compatible with iOS, and for Android you would register with template compatible for Android. Then, when you send your message, it will be formatted accordingly.
We did it even little bit differently compared to Microsoft example. Our clients (iOS or Android) provide template, so backend developers don't need to know those details. More here: http://discoveringdotnet.alexeyev.org/2014/07/registration-for-azure-notification-hub.html