Azure通知中心设备注册



自从AppCenter在今年年底退休以来,我已经开始迁移到Azure通知中心。但通知中心的文档并不清楚。特别是Xamarin.Android的文档。它与他们最新的SDK不匹配。

在最新的(1.1.1版本(azure notification hub SDK for Android(或Xamarin.Android(中,不需要实现FirebaseMessagingServiceNotificationHub.Start()方法在Notification Hub中注册设备。以这种方式注册的设备可以毫无问题地获得通知。

NotificationHub.Start(Application, <HubName>, <ConnectionString>);

使用新的SDK,向现有NotificationHub实例添加标记也很简单。

NotificationHub.AddTag("username:user123");

但在注册管理中,官方文档指出,设备可以从客户端或服务器端向通知中心注册。如果我的应用程序使用NotificationHub.Start()方法在通知中心注册,是否需要使用其中一种方法?还是我错过了什么?

此外,当我使用AppCenter时,我使用了AppCenter InstallId来针对特定的设备。考虑到这一点,是否可以使用NotificationHub.InstallationId作为标签(例如:"handle:<devce's InstallationId>"(发送特定于设备的通知?

如果我的应用程序使用NotificationHub.Start((方法在通知中心注册,是否需要使用其中一种方法?

当您调用NotificationHub.start(Application, ...)时,Android SDK将侦听更改,如添加的标签、新的FirebaseMessagingService令牌等。每当检测到更改时,它都会调用InstallationAdapter来通知后端新的详细信息。

默认的InstallationAdapter将向Azure通知中心后端发送PUT请求,如本文所述。这就是NotificationHub.start(Application, string, string)所创建的;对于那些没有托管自己后端的人来说,这是一个合理的默认设置。

如果您有自己的后端来跟踪设备,或者您只是想将凭据保留在服务器端,那么您可以将InstallationAdapter换成一个调用API的类。您所需要做的就是实现InstallationAdapter接口,并通过调用NotificationHub.start(Application, InstallationAdapter)来初始化SDK。

如果使用如上所述的NotificationHub.start(...)方法,则不需要进一步的注册操作。

考虑到这一点,是否可以使用NotificationHub.InstallationId作为标记(例如:"handle:<devce's InstallationId>"(发送设备特定通知?

是的!本文档将引导您了解如何使用特殊标记格式$InstallationId:{YOUR_TAG_ID}来针对特定设备。

当您使用了NotificationHub.start()时,如果您没有指定InstallationId,它将为您生成一个。

关于设置InstallationId和/或UserId的问题。如果我使用的是Microsoft.Azure.NotificationHubs.Client,那么这样做更有意义。

我应该通过$InstallationId标记设置InstallationId吗(请参阅此处:https://learn.microsoft.com/en-us/azure/notification-hubs/notification-hubs-push-notification-registration-management#installations)或者通过实现InstallationEnrichmentAdapter并通过对安装的调用进行设置。EnrichInstallation方法中的InstallationId=?

此外,Microsoft.Azure.NotificationHubs.Client.Installation类还提供了一个UserId属性,该属性也可以更新。

我还将推送通知从AppCenter转移到Azure通知中心,并希望重用我现有的AppCenterInstallId

我可以添加标签和用户ID,如下所示(java(

NotificationHub.start(this.getApplication(), BuildConfig.hubName, BuildConfig.hubListenConnectionString);
NotificationHub.setInstallationId("123");
Set<String> tags = new HashSet<>();
tags.add("role_memeber");
NotificationHub.setUserId("123");
NotificationHub.addTags(tags);

sdk:microsoft.azure:通知中心android sdk:1.1.6

最新更新