简体   繁体   English

如何在C#后端中设置Azure Notification Hub

[英]How to setup Azure Notification Hub in C# backend

I'm trying to implement my C# backend's communication with Notification Hub. 我正在尝试通过Notification Hub实现C#后端的通信。 I've read almost every tutorial about Azure Notification Hub, and I can't find a decent tutorial that explains what actually corresponds to what. 我已经阅读了几乎所有有关Azure Notification Hub的教程,但找不到合适的教程来解释实际与实际相对应的内容。 I think there are two ways of representing a device (from what I've understood): an Installation and Registration, and Installation seems to be newer and more preferred. 我认为有两种表示设备的方式(据我所知):安装和注册,以及安装似乎是较新的且更可取的。

However, when I get into Installation, I get more questions in my mind: 但是,当我进入安装时,我会想到更多问题:

What is InstallationId ? 什么是InstallationId Is it something that I create, or something that I get from somewhere , either device or PNS. 是我创建的东西,还是从设备或PNS的某个地方得到的东西。

Do I need to set up ExpirationTime , or does it default to longest (it says 90 days is the longest)? 我需要设置ExpirationTime还是默认为最长(它表示最长为90天)? What if I want it to be longer than 90 days? 如果我希望超过90天该怎么办?

What is PushChannel ? 什么是PushChannel Is it, just like InstallationId , something that I create, or get from somewhere? 就像InstallationId一样,是我创建的东西,还是从某个地方得到的东西?

How are templates exactly used? 如何正确使用模板?

Out of all these variables, which one is the actual device push token that I get at the client? 在所有这些变量中,我在客户端获得的实际设备推送令牌是哪一个?

I usually don't ask those kind of questions that seek for a tutorial-ish answers and have multiple questions, but I've tried to search everywhere, but the more I search, the more it gets complicated and I don't even know where to start. 我通常不会问那些寻求教程式答案并且有多个问题的问题,但是我尝试在任何地方进行搜索,但是搜索的次数越多,它变得越复杂,我什至不知道从哪儿开始。 Any answer would be a good starting point to anyone trying to learn Notification Hubs, just like me. 对于像我一样尝试学习通知中心的任何人,任何答案都是一个很好的起点。

InstallationId is an abstraction on top of device token/key/channel etc. It's a unique id that you create when you 'install' a device (or user if your OS/platform allows separate tokens for multiple users). InstallationId是设备令牌/密钥/通道等之上的抽象。它是在“安装”设备(或用户(如果您的OS /平台允许多个用户使用单独的令牌)时)创建的唯一ID。 This is an id you can use to associate tags, templates etc with the device. 这是一个ID,您可以用来将标签,模板等与设备相关联。 You create an installation once and then keep the id somewhere in the local storage and then make updates to the installation associated with the id if you need to. 创建一次安装,然后将ID保留在本地存储中的某个位置,然后根据需要更新与该ID关联的安装。

You don't need to explicitly set ExpirationDate . 您无需显式设置ExpirationDate I think in the past tokens on most platforms used to expire, so this was a way to let Notification Hubs know when not to try to push to the token. 认为过去大多数平台上的令牌过去都已经过期,因此这是一种让通知中心知道何时不尝试推送令牌的方法。 I believe now it's not the case. 相信现在并非如此。 So what happens is if Notification Hubs cannot deliver a notification to a device for a number of times, it just deletes the registration by itself. 因此,发生的情况是,如果Notification Hubs多次无法将通知传递到设备,它只会自行删除注册。

Has this post on templates been useful? 这个关于模板的帖子有用吗?

PushChannel stands for 'The channel URI if registering the installation for WNS; PushChannel 代表 “如果注册WNS安装,则通道URI; Device Token if registering for APNS.' 如果注册APNS,则为设备令牌。”

Let me know in the comments if I can clarify any of these and I'll update the answer. 如果可以澄清这些问题,请在评论中告诉我,我将更新答案。

There is actually a 3rd option besides Installation and Notification : DirectSend . 除了Installation and NotificationDirectSend实际上还有第三个选项。

The Direct-Send technique is less of an abstraction than Installation and Notification . Direct-Send技术比Installation and Notification 了一种抽象。 With Direct-Send you can send notifications directly to one or more specific devices. 使用Direct-Send您可以将通知直接发送到一个或多个特定设备。 Basically you use the actual deviceToken - as in what @NikitaG notes for PushChannel . 基本上,您使用实际的deviceToken就像@NikitaG注意的PushChannel

If you need to be able to decide specifically when your back-end application pushes to a specific-device-A-but-not-B vs. pushing to a specific-device-B-but-not-A vs. specific-device-A-and-specific-device-B according to some schedule Direct-Send can be enabling. 如果您需要能够专门决定何时后端应用程序推送到特定设备而不是B而不是推送到特定设备B但不是A还是特定设备-A和特定设备B根据某些时间表可以启用Direct-Send

I'd listed some of the resources discussing Direct-Send at Azure Notification Hubs Send Notification to Specific Device . 我列出了一些在Azure Notification Hubs向特定设备发送通知上讨论Direct-Send的资源。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM