2

I would like to use Azure Notification Hubs to send push notifications to users of my app running across iOS, Android and Windows Phone.

I have managed to get the basics working but I don't know how to manage the App uninstall story.

On starting, the mobile app will call my Identity Svc to get an Auth Token. It then calls its Platform Notification service (eg Google Cloud Messaging, APNS) to get a PNS Token. After persisting the token to local storage it will call a back-end Contact Svc to register the customer's device. This service will create a subscription to the Azure Notification hub for the device.

This is illustrated in the following diagram:

enter image description here

Later on a back-end publishing service will call the Contact Service requesting a push notification for a particular user id. The contact service will lookup the Id allocated to a tag on the notification hub and send a push request.

What options are available to determine when a customer uninstalls the app? Is it just a matter of trapping errors when calling "Send" on the notification hub? I guess this could work if only sending to a single user but my intention is that certain message types are to be published to multiple subscribers. On the initial registration of a device a subscription will be created for a tag of the user id but also for a more general tag such as "New Promotion". The publishing service would later want to issue a "New Promotion" notification to all devices.

Rob Bowman
  • 7,632
  • 22
  • 93
  • 200
  • Hi there - I have the same problem. When I uninstall the app on ios the push registration is automatically deleted from my notification hub registrations. Although when I uninstall the app on android the notification hub keeps the registration for some reason - really don't know why (maybe because my app is in test mode and not live or is there any other reason???). Now the problem is that the 2nd installation gets a new handle (deviceToken) from google and thus a new registration is issued by my server which leads to multiple push messages. Any ideas how to solve this? welcome! @eliodamaggio – Freddy Jul 08 '15 at 23:24

1 Answers1

4

Why do you need to know app uninstalls?

Notification Hubs automatically expire registrations for devices that get uninstalled. Also, I would avoid persisting the PNSHandles in your service at all.

The current guidelines for using hubs are the following:

store the registrationIds of the registrations associated with the device in local storage. This enables you to update tags and channel information with a single update call. Because mobile connections are not always reliable, it is best to avoid creating a new registration without being able to store the registrationId in local storage. This can result in the device registering multiple times, causing duplicate notifications. You can achieve this by using the Create Registration ID and Create or Update Registration REST APIs. The first API returns a registrationId without actually creating a registration. When the ID has been securely stored on the device storage, the device can call the Create or Update Registration API.

So I would have your ContactSvc expose two functionalities: a) create registration id (just call hub to get it) b) create or update registration given (registrationId, pnsHandle, tags?)

Then your device keeps the regId in its storage, ad after getting the handle from PNS, if as regId is not there creates a new one with endpoint a), then updates the registration with pnsHandle and tags.

Note that in this way your service does not need to persist handles or UUIDs, and does not need to worry about app uninstalls.

If you are keeping track of users, one approach is to periodically (once a month?) check in your hub if its registrations are still there...

You can reach me at @eliodamaggio if this is not clear.

Elio Damaggio
  • 862
  • 4
  • 6
  • Thanks for your comments Elio, I found them helpful. I'm not clear on how Notification Hubs "automatically expire registrations", could you please elaborate. – Rob Bowman Mar 31 '14 at 11:16
  • I got it - registration on a hub has a time to live maximum of 90 days. Not sure how to set the ttl though? – Rob Bowman Mar 31 '14 at 15:47
  • 1
    I just uninstalled an app and the registration ID is still in the notification hub. – Questioner Dec 06 '16 at 11:35
  • Hi, I have also facing same problem receiving push notifications after uninstall app from my android device. I have used xamarin android with azure push notifications hub. How can I fixed this issue. – Deepak Dec 02 '17 at 04:38
  • 2020 and same deal - registering with Firebase tokens. After reinstall there's a new one, but the old registration does not go away from Azure. We can play manual cleanup for some ID's we have in storage, but many ID's are just gone so there's no way to unregister programmatically it would seem, nor via Azure site that I can see. So there are plenty of dead/moot devices. Seems a profitable issue for Microsoft to ignore since they sell tier plans based on number of devices. – Josh Sutterfield Jul 20 '20 at 23:39