1

I have a native iOS and Android app, plus web app (using React), that I want to send notifications for. I have setup Firebase Cloud Messaging, and am able to receive notifications when calling the FCM send API with a "to" field using an FCM Token.

The issue I am facing comes from this ... I want to allow users to have custom notification settings for each device that they are signed into. For example, we will offer notifications for multiple events such as:

  • When a user completes a workout
  • When a user gets a new max record for a specific exercise
  • New chat message

As an example ... We want the ability to allow someone to choose that they want to receive the first two notification event types in their iPhone 11, but only receive the chat message event type in their iPhone SE. Also, they want to receive the 2nd and 3rd notification type in their Chrome Browser.

This is how Skype works, for example ... where each device can choose it's own custom notification settings, independent of the settings chosen on other devices.

I cannot figure out the best way to manage this though. I have created a database table like this:

| UserDeviceId | UserId | DeviceType | FCMToken |
|--------------|--------|------------|----------|
| 1            |    1   | iOS        | adfgaf   |
| 2            |    1   | Android    | hgjadf   |
| 3            |    1   | Web        | adfg     |
| 4            |    1   | iOS        | adgh     |
| 5            |    2   | iOS        | hankn    |

Then I have a settings table like:

| SettingsId | UserDeviceId | NotificationTypeId |
|------------|--------------|--------------------|
| 1          | 1            | 1                  |
| 2          | 1            | 2                  |
| 3          | 2            | 1                  |
| 4          | 3            | 2                  |
| 5          | 5            | 1                  |

The issue here is that the FCM tokens CAN change, and I don't have any control over that ... but also, the FCM token is NOT user-specific. So, if I log out of a device and someone else logs in, then they will have the SAME FCM token ... which obviously causes an issue.

So, when someone logs out, I would need to remove this token for their user (and could add again, if they re-login). But how then should I save their notification settings, so that all their settings are not just deleted if they log out, but instead, they could log back in and their settings remain. I have read a little about getting a user device id here and here. But I am unsure for web ... as in this case, a new FCM token is provided for each Browser the user uses (so maybe we can condense all the WEB notifications to 1 setting type).

Does anyone have ideas or suggestions on this idea, or how they have handled similarly in their apps?

Ridge Robinson
  • 738
  • 1
  • 8
  • 19

0 Answers0