Skip to content

Android/iOS/browser notifications #1561

Closed

Description

@tluyben

We use Firebase currently for the easy of handling multi platform notifications: is this planned ( I could not find mention of it ) and otherwise, is it something that could be considered as a future feature?

Activity

  1. added
    enhancement
    on May 14, 2021
  2. tannermeade commented on Jun 10, 2021

    @tannermeade

    This is a great feature and there are a lot of opportunities to bring a lot of value to Supabase in push notifications. Here are some details about push notifications:

    How Push Notifications Work

    • Both Android/iOS have a need to quickly push notifications and data to the devices from a server-initiated event. To avoid multiple apps constantly polling for new data/notifications, both platforms have implemented a single connection between the device and a server that apps can use to send push notifications/data. Android uses Firebase Cloud Messaging (FCM) and iOS uses Apple Push Network (APNS). Huawei devices use their own service called HMS Push Kit. FireOS devices use Amazon SNS.
    • You can not implement your own reliable push notification system without using the FCM/APNS connection between Apple/Google's server and the device. Firebase/APNS must be used. This is because iOS/Android regulates the background services that would be required on the device to establish such a connection when an app is not in the foreground. (example: if the developer is doing everything right, at best iOS will run a background service with an interval of 15 minutes)
    • On some Android devices it is slightly possible to make your own ongoing background service, however, as you can see here (https://dontkillmyapp.com) Android is very fragmented in how it handles background services. Google is also making Android increasingly more strict for background services. It is not a viable solution to implement it all yourself.
    • When using the firebase client libraries, FCM (serverside) will forward push notifications to APNS. FCM tries to act as a single source you need to tell to push to all your devices.

    Some Downsides to FCM/APNS

    • APNS stores only the most recent notification per device and per app. If a device is offline, sending a notification request targeting that device causes the previous request to be discarded. If a device remains offline for a long time, all its stored notifications in APNS are discarded. (FCM stores all notifications for a max of ~4 weeks when proper attributes are set)
    • Neither FCM/APNS provides a delivery status. If Firebase has the correct analytics configuration, after 24 hours push delivery status is available through Big Query (not helpful programmically). The message a server gets when pushing to a device is only an indication that FCM/APNS successfully received the request to push to the device. This is a place where Supabase could provide a lot of value.

    Moving Forward

    • The scope of this feature could be very small or incredibly vast, but that depends on Supabase and what they choose.
    • Another YC company called OneSignal (https://onesignal.com) exists expressly just to solve this problem.
    • The discussion here should probably be centered on what the scope of the solution should be.
    • This feature is probably a bit more of a convenience feature since FCM/APNS will still be used. I wouldn't wait around for it.
  3. k0shk0sh commented on Jul 28, 2021

    @k0shk0sh

    I would like to mention a temporary using procedure functions and http extension for postgres with them i was about to send pushes using triggers on a table called notifications, for anyone who is struggling with this until workflows come out, here is an example how you can do this:

    first create a trigger on your table:

    create trigger notification_inserted
    after
    insert
      on notifications FOR EACH ROW EXECUTE PROCEDURE on_notification_created();
    

    on_notification_created basically, construct some data and eventually call this method below::

    create
    or replace function send_push(
      push_token text,
      title text,
      body text,
      ref_id uuid,
      creator_id uuid,
      n_type text
    ) returns void as $$
      SELECT
      status,
      content
      FROM
        http(
          (
            'POST',
            'https://fcm.googleapis.com/fcm/send',
            ARRAY [ http_header(
              'Authorization',
              'key=myawesomekey'
            ),
            http_header('Content-Type', 'application/json') ],
            'application/json',
            (
              select
                get_fcm_body(
                  push_token,
                  title,
                  body,
                  ref_id,
                  creator_id,
                  n_type
                )
            )
          ) :: http_request
        );
    $$ language sql;
    

    and here is the message that construct the json object

    create
    or replace function get_fcm_body(
      push_token text,
      title text,
      body text,
      ref_id uuid,
      creator_id uuid,
      n_type text
    ) returns json AS $$
    declare
      notification json;
      n_data json;
    begin
        notification := json_build_object(
          'title', title,
          'body', body,
          'clickAction', 'FLUTTER_NOTIFICATION_CLICK',
          'sound', 'default',
          'tag', ref_id::text
        );
    
        n_data := json_build_object(
          'title', title,
          'body', body,
          'type', n_type,
          'refId', ref_id,
          'creatorId', creator_id::text
        );
        
    return json_build_object(
        'to', push_token,
        'notification', notification,
        'data', n_data
    );
    end;
    $$ language plpgsql;
    

    I hope this help everyone facing such issue and wants to use one service for everything.

  4. xiki808 commented on Oct 26, 2021

    @xiki808

    Would also be great to be able to run the requested push notification feature in a LAN and without the need of the internet. This is especially helpful for smart home solutions, and many other cases.

  5. locked and limited conversation to collaborators on May 4, 2022
  6. converted this issue into a discussion #6690 on May 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions