pusher / push-notifications-flutter

Official Pusher Beams Flutter client plugin (iOS, Android and Web), receive notifications easily on your Flutter application with Pusher Beams.
https://pub.dev/packages/pusher_beams
MIT License
10 stars 21 forks source link

Add a `getInitialMessage` method to accomplish deep-linking from a Push Notification #22

Closed esarbanis closed 2 years ago

esarbanis commented 2 years ago

The inspiration for this method comes from Firebase's getInitialMessage. It is a good way to accomplish deep-linking from a Push Notification.

For example, I want to send a push notification to the users of a chatroom, that a new message was posted. I would also like for my users to be navigated to that chatroom when they tap on the notification. With this implementation, I can add data that can be used by my app to do the navigation, in the Push Notification message inside the data part of it.

TLDR; Send this message via pusher:

{
  "interests": ["hello"],
  "apns": {
    "aps": {
      "alert": {"title":"Hello", "body":"Hello, world!"}
    },
   "data": {
      "info": { "name": "george" }
    }
  },
  "fcm": {
    "notification": {"title":"Hello", "body":"Hello, world!"}
    "data": {
      "info": { "name": "george" }
    }
  }
}

And you can get it if the user opens the app by tapping on the notification:

final message = await PusherBeams.instance.getInitialMessage(); //{ "name": "george" }
if(message != null) {
  _navigate(message);
}

We already use this patch in our production app, it would be nice to switch back to the official version

georgiosd commented 2 years ago

This is great! I hope the pusher team will have a chance to review this.