【发布时间】:2018-03-29 00:24:30
【问题描述】:
我正在使用azure-mobile-apps-node 注册并通过 GCM 发送推送通知。我使用 push.patchInstallation 注册通知客户端,如下所示:
var updateOperation = [{
'op': 'replace',
'Path': '/tags',
'Value': tags.join()
}];
push.patchInstallation(installationId, updateOperation, function (error, res) { /*...*/ };
而且效果很好,看看通知中心的注册,我明白了
<GcmRegistrationDescription xmlns="http://schemas.microsoft.com/netservices/2010/10/servicebus/connect" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<ETag>13</ETag>
<ExpirationTime>9999-12-31T23:59:59.9999999Z</ExpirationTime>
<RegistrationId>1234568266548022282-123456473823493176-1</RegistrationId>
<Tags>$InstallationId:{SOME_GUID},location_1,location_2,location_3,userId:myaccount@domain.com</Tags>
<GcmRegistrationId>SOME_ID</GcmRegistrationId>
</GcmRegistrationDescription>
但是,如果我尝试使用标签“location_N”推送通知,它永远不会起作用。还尝试了多个设备都已注册到特定 location_N 并且它们都没有获得推送更新。
我确定这是由于 azureMobile 应用程序 patchInstallation 作为第一个标记注入的 $InstallationId:{SOME_GUID}。
- 如果我使用 REST API 并将注册标签修改为 location_N,并将推送发送到该标签,它可以正常工作。
- 如果我将推送发送到标签 $InstallationId:{SOME_GUID},推送将通过该特定设备。
- 如果我使用标签 $InstallationId:{SOME_GUID} || location_N,只有具有安装 ID 的设备才能收到推送通知。
这只是使用安装方法时的限制,还是一个错误,或者我完全误解了什么?
编辑 19.10.2017: 我修改了我的代码以使用注册模型,即
notificationHubService.gcm.createOrUpdateNativeRegistration(registrationId, installation.pushChannel, tags.join(), function(error, res) { /*...*/ }
它不会将 $InstallationId 注入标签,而是创建两个具有相同 GcmRegistrationId 但具有不同标签的注册,一个具有 $InstallationId
<RegistrationId>REGID1</RegistrationId>
<Tags>$InstallationId:{SOMEGUID},_UserId:sid:SOMESID</Tags>
<GcmRegistrationId>GCMREGID</GcmRegistrationId>
另一个只有我在 createOrUpdateNativeRegistration
中定义的标签<RegistrationId>REGID2</RegistrationId>
<Tags>location_1,location_2,location_3</Tags>
<GcmRegistrationId>GCMREGID</GcmRegistrationId>
有了这个,我可以使用 location_N 标签将推送消息发送到我的测试设备(也可以使用 $InstallationId 发送到特定设备),因此两种注册都有效。我不知道为什么它会创建两个注册,因为我在任何时候都没有对 notificationHubService.createRegistrationId 的任何调用,只是对 createOrUpdateNativeRegistration 的单个调用。
【问题讨论】:
-
我建议您关注here 来解决此问题。
-
那篇文章没有讨论这个问题,抱歉。
标签: javascript azure-mobile-services azure-notificationhub