Usage of Azure Notification Hubs templateName

試著忘記壹切 提交于 2020-01-14 07:23:08

问题


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?


回答1:


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...




回答2:


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



来源:https://stackoverflow.com/questions/25282403/usage-of-azure-notification-hubs-templatename

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!