我使用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。
我建议您按照[此处](https://docs.microsoft.com/zh-cn/azure/notification-hubs/notification-hubs-push-notification-fixer)来解决此问题。 –
那篇文章不讨论这个问题,对不起。 –