简体   繁体   English

带有$ InstallationId标记的Notification Hub推送问题

[英]Notification Hub push issue with $InstallationId tag

I'm using azure-mobile-apps-node to register and send push notifications via GCM. 我正在使用azure-mobile-apps-node来注册并通过GCM发送推送通知。 I register notification clients using push.patchInstallation like this: 我使用push.patchInstallation注册通知客户端,如下所示:

var updateOperation = [{
    'op': 'replace',
    'Path': '/tags',
    'Value': tags.join()
}];

push.patchInstallation(installationId, updateOperation, function (error, res) { /*...*/ };

And it works well, looking at the Notification Hub registrations, I see 它运行良好,查看Notification Hub注册,

<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>

However, if I try to push notifications using the tag "location_N", it never works. 但是,如果我尝试使用标签“ location_N”推送通知,则它将永远无法工作。 Have also tried with multiple devices both having registered to specific location_N and none of them gets the push updates. 还尝试了多个都已注册到特定location_N的设备,但它们均未获得推送更新。

I've determined this to be due to the $InstallationId:{SOME_GUID} that the azureMobile apps patchInstallation injects as first tag. 我确定这是由于azureMobile应用程序patchInstallation将第一个标签注入的$ InstallationId:{SOME_GUID}引起的。

  • If I use REST API and modify registration Tags to location_N, and send push to that tag, it works fine. 如果我使用REST API,并将注册标签修改为location_N,然后将推送发送到该标签,则效果很好。
  • If I send push to tag $InstallationId:{SOME_GUID} , push goes through to that specific device. 如果我将推送发送给标签$ InstallationId:{SOME_GUID} ,则推送将转到该特定设备。
  • If I use tag $InstallationId:{SOME_GUID} || 如果我使用标签$ InstallationId:{SOME_GUID} || location_N , only device with the installation ID gets the push notification. location_N ,只有具有安装ID的设备才能获得推送通知。

Is this just limitation when using the Installation method, or is it a bug, or have I completely misunderstood something? 这是使用安装方法时的限制,还是一个错误,或者我是否完全误解了某些内容?

EDIT 19.10.2017: I modified my code to use the Registration model, ie, 编辑19.10.2017:我修改了代码以使用注册模型,即

notificationHubService.gcm.createOrUpdateNativeRegistration(registrationId, installation.pushChannel, tags.join(), function(error, res) { /*...*/ }

which doesn't inject the $InstallationId to tags, but instead creates two registrations with same GcmRegistrationId, but with different Tags, one with the $InstallationId 不会将$ InstallationId注入标签,而是使用相同的GcmRegistrationId创建两个注册,但使用不同的Tag,其中一个使用$ InstallationId

<RegistrationId>REGID1</RegistrationId>
<Tags>$InstallationId:{SOMEGUID},_UserId:sid:SOMESID</Tags>
<GcmRegistrationId>GCMREGID</GcmRegistrationId>

and the other with just the tags I define in createOrUpdateNativeRegistration 另一个仅带有我在createOrUpdateNativeRegistration中定义的标签

<RegistrationId>REGID2</RegistrationId>
<Tags>location_1,location_2,location_3</Tags>
<GcmRegistrationId>GCMREGID</GcmRegistrationId>

With this I'm able to send push messages to my test devices using location_N tags (and also to specific device using the $InstallationId), so both registrations work. 这样我就可以使用location_N标签将推送消息发送到我的测试设备(也可以使用$ InstallationId发送到特定设备),因此这两个注册都可以工作。 I have no idea why it creates two registrations as I don't have any calls to notificationHubService.createRegistrationId in any point, just single call to createOrUpdateNativeRegistration . 我不知道为什么要创建两个注册,因为在任何时候我都没有对NotificationHubService.createRegistrationId的任何调用,仅是对createOrUpdateNativeRegistration的一次调用。

This is a valid scenario. 这是一个有效的方案。 You should be able to push notifications using the location_N tag. 您应该能够使用location_N标签推送通知。 Could you try 'test send' in portal.azure.com to verify that devices are selected for push notification? 您能否在portal.azure.com中尝试“测试发送”以验证是否选择了用于推送通知的设备?

Based on your description, you are using the Installation model, and a system tag $InstallationId:[installationId] is automatically added with your installation, you could send to this tag to target a specific device. 根据您的描述,您正在使用安装模型,并且系统标记$InstallationId:[installationId]将随安装自动添加,您可以将其发送到此标记以定位特定的设备。

From your code, you are using the JSON-Patch standard for updating your tags on the registration. 从代码中,您正在使用JSON-Patch标准来更新注册中的标签。 You replaced your tags with a single string tag via tags.join() . 您通过tags.join()将标签替换为单个字符串标签。

For replacing multiple tags for your installation, you need to specific your updateOperation as follows: 要替换多个标签进行安装,您需要按如下方式updateOperation

var updateOperation = [{
    'op': 'replace',
    'Path': '/tags',
    'Value': tags //An array of tags.
}];

Moreover, you could try to read your installation and check your tags to narrow this issue. 此外,您可以尝试阅读安装并检查标签以缩小此问题。

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

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