使用$ InstallationId标记的通知中心推送问题
我使用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:[email protected]</Tags>
<GcmRegistrationId>SOME_ID</GcmRegistrationId>
</GcmRegistrationDescription>
不过,如果我尝试使用标签来推送通知“location_N”,它永远不会工作。也曾尝试使用多个设备注册到特定的location_N,但没有一个获得推送更新。
我确定这是由于$ InstallationId:{SOME_GUID} azureMobile应用程序patchInstallation注入作为第一个标记。
- 如果我使用REST API并修改注册到location_N的标签,并发送推送到该标签,它工作正常。
- 如果我发送推送到标签$ InstallationId:{SOME_GUID},推送到该特定设备。
- 如果我使用标签$ InstallationId:{SOME_GUID} || location_N,只有具有安装ID的设备才会获取推送通知。
这只是使用安装方法的限制,还是一个错误,或者我完全误解了一些东西?
编辑2017年10月19日: 我修改代码来使用注册模型,即
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 0定义标签
<RegistrationId>REGID2</RegistrationId>
<Tags>location_1,location_2,location_3</Tags>
<GcmRegistrationId>GCMREGID</GcmRegistrationId>
有了这个我能推送消息发送到使用location_N标签我的测试设备(也使用$ InstallationId特定的设备),这样既注册工作。我不知道为什么它创建了两个注册,因为我没有任何呼叫notificationHubService.createRegistrationId在任何时候,只需要拨打createOrUpdateNativeRegistration。
这是一个有效的场景。您应该能够使用location_N标签推送通知。您是否可以尝试在portal.azure.com上的“测试发送”来验证是否选择了推送通知设备?
谢谢你确认它应该工作。但是,无论我使用Postman通过REST发送通知还是使用Azure Test Send,如果第一个标记为$ InstallationId,它都不会找到带标记的注册。 Azure Test Send说:'邮件已成功发送,但没有匹配的目标。' –
根据您的描述,您使用的是安装模型和系统标签$InstallationId:[installationId]
会自动安装添加,您可以发送到这个标记来针对特定的设备。
从您的代码中,您正在使用JSON-Patch standard更新注册时的标签。您通过tags.join()
替换了单个字符串标签的标签。
对于替代多个标签为您的安装,你需要特定的updateOperation
如下:
var updateOperation = [{
'op': 'replace',
'Path': '/tags',
'Value': tags //An array of tags.
}];
此外,你可以尝试阅读您的安装并检查您的标记,以缩小这一问题。
我相信这不会改变一件事情,因为无论我如何做,最终的结果是
从您的测试看来,它似乎只能在使用安装模型时使用标签'$ InstallationId:{SOME_GUID}'发送推送。您是否尝试通过代码检索您的安装并检查您的有效标签? –
是的,提取安装表明标签是有效的,即
我建议您按照[此处](https://docs.microsoft.com/zh-cn/azure/notification-hubs/notification-hubs-push-notification-fixer)来解决此问题。 –
那篇文章不讨论这个问题,对不起。 –