skip to Main Content

I have implemented push notifications using FCM in my Flutter app.
Next, I want to allow users to control the ON/OFF state of receiving push notifications based on their content (similar to receiving push notifications for "likes" on their own posts in a social media app) from the Flutter app (client) side.

I couldn’t find a specific implementation method while researching, so I would like to ask here for advice on how to achieve this.

The method I have considered is to save the settings for each user’s push notification items in Firestore. During push notification sending, the app will check the saved values and decide whether to include the notification in the payload based on those values.

However, this approach requires storing data for each push notification item (e.g., "like" or "mention") in Firestore, and there will be multiple communications with Firestore each time the client changes the push notification settings. This could result in increased network communication and overhead.

So, besides the method of saving the push notification enable/disable value in Firestore and checking it every time an FCM message is sent, are there any other methods to determine whether to perform push notifications on the client side for each push notification item?

2

Answers


  1. Hope this works:
    You can use a local database like SharedPreferences or Hive to save user notifications peferences and when recieving notifications, you can filter out from stream, the preffered notifications.

    Another way would be, Sending the preference as Header instead of payload to the server and let the server filter out the notifications for the user.

    Last but not the least, Pub/Sub model. Read more here.

    FCM offers topic-based subscriptions, enabling users to subscribe or unsubscribe from specific topics. When a user updates their notification settings, you can manage their topic subscriptions accordingly. By targeting the relevant topic(s) when sending a push notification, FCM takes care of delivering the message only to devices that are subscribed to those topics. This way, you can efficiently control which users receive specific types of push notifications based on their preferences.

    Login or Signup to reply.
  2. You are on the right track with your approach of saving the push notification enable/disable settings in Firestore and checking them when sending FCM messages. However, I understand your concern about potential network communication overhead. To minimize the communication with Firestore, you can consider using a combination of local storage and Firestore to efficiently handle push notification settings on the client-side.

    Here’s a suggested approach:

    • Local Storage: Store Push Notification Settings Locally When the user
      opens the app, you can fetch their push notification settings from
      Firestore and store them locally on the device (e.g., using
      SharedPreferences or other local storage options available in
      Flutter). This way, you can avoid repeated network requests for the
      same data during the user’s session.

    • Sync with Firestore on App Start or Resume At app startup or when the
      app resumes from the background, you can check if there have been any
      changes to the push notification settings on the Firestore side. If
      the settings have been updated, you can sync the local storage with
      the latest values from Firestore. This ensures that the app always
      has the most up-to-date settings without querying Firestore every
      time you need the data

    • Use Local Settings to Determine Push Notification Eligibility When
      it’s time to send a push notification, you can directly check the
      local storage to determine whether the specific push notification
      type is enabled or disabled for the user. This approach eliminates
      the need to make an additional Firestore request for each
      notification and reduces overhead.

    • Periodic Sync or On-Demand Sync If you want to ensure the local
      settings are up-to-date, you can periodically sync them with
      Firestore (e.g., once a day or on specific events). Additionally, you
      can provide an option for users to manually trigger a sync in the app
      settings if they want immediate updates.

    • By using a combination of local storage and periodic or on-demand
      syncing, you can strike a balance between keeping the push
      notification settings up-to-date and minimizing unnecessary network
      communication. This approach is especially useful when dealing with
      large user bases and frequent settings changes.

    Remember to handle edge cases gracefully, such as handling situations where the device is offline during sync attempts, to provide a smooth user experience.

    Overall, this approach should help you efficiently manage push notification settings on the client-side without putting excessive load on the Firestore database.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search