简体   繁体   中英

Notification Hub push issue with $InstallationId tag

I'm using azure-mobile-apps-node to register and send push notifications via GCM. I register notification clients using push.patchInstallation like this:

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

<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. Have also tried with multiple devices both having registered to specific location_N and none of them gets the push updates.

I've determined this to be due to the $InstallationId:{SOME_GUID} that the azureMobile apps patchInstallation injects as first tag.

  • If I use REST API and modify registration Tags to location_N, and send push to that tag, it works fine.
  • If I send push to tag $InstallationId:{SOME_GUID} , push goes through to that specific device.
  • If I use tag $InstallationId:{SOME_GUID} || location_N , only device with the installation ID gets the push notification.

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,

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

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

and the other with just the tags I define in 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. 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 .

This is a valid scenario. You should be able to push notifications using the location_N tag. Could you try 'test send' in portal.azure.com to verify that devices are selected for push notification?

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.

From your code, you are using the JSON-Patch standard for updating your tags on the registration. You replaced your tags with a single string tag via tags.join() .

For replacing multiple tags for your installation, you need to specific your updateOperation as follows:

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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