MBurger Engagement Platform
User GuideHeadless CMSEngagement Platform
  • 🍔MBurger Engagement Platform 🍔
  • 🍏 iOS Docs
    • Messages
      • Installation
      • Initialization
      • Push notifications
        • Rich Notifications
      • Stylize in app messages
      • Message Metrics
    • Audience
      • Installation
      • Initialization
      • Tracked data
      • Tags
      • Identify a user
      • Location
    • Automation
      • Installation
      • Initialization
      • Triggers
      • Send events
      • View Tracking
  • 📱Android Docs
    • Messages
      • Prerequisites for Push Notifications
      • Installation
      • Initialization
      • Stylization and parameters
      • Push notifications
      • Message Metrics
    • Audience
      • Installation
      • Initialization
      • Tracked data
      • Tags
      • Custom Id
      • Mobile User Id
      • Location Data
    • Automation
      • Installation
      • Initialization
      • Triggers
      • Add events
      • View Tracking
      • Stop/Pause tracking
  • 🔷Flutter Docs
    • Messages
      • Installation
      • Initialization
      • Stylize in app messages
      • Push notifications
        • Rich Notifications
      • Message Metrics
    • Audience
      • Installation
      • Initialization
      • Tracked data
      • Tags
      • Custom Id
      • Mobile User Id
      • Location Data
    • Automation
      • Installation
      • Initialization
      • Triggers
      • Send events
      • View Tracking
Powered by GitBook
On this page
  • Request a token
  • Register to topics
  • MBurger topics
  • Launch notification

Was this helpful?

  1. Flutter Docs
  2. Messages

Push notifications

PreviousStylize in app messagesNextRich Notifications

Last updated 4 years ago

Was this helpful?

With this plugin you can also manage the push notification section of MBurger, this is a wrapper around MPush, the underlying platform, so you should refer to the to understand the concepts and to start the push integration. In order to use MBMessages instead of MPush you have to do the following changes:

Set the push token like this:

MBPush.pushToken = "YOUR_PUSH_TOKEN";

Configure the callbacks and Android native interface like this:

MBPush.configure(
  onNotificationArrival: (notification) {
    print("Notification arrived: $notification");
  },
  onNotificationTap: (notification) {
    print("Notification tapped: $notification");
  },
  androidNotificationsSettings: MPAndroidNotificationsSettings(
    channelId: 'messages_example',
    channelName: 'mbmessages',
    channelDescription: 'mbmessages',
    icon: '@mipmap/icon_notif',
  ),
);

To configure the Android part you need to pass a MPAndroidNotificationsSettings to the configure sections, it has 2 parameters:

  • channelId: the id of the channel

  • channelName: the name for the channel

  • channelDescription: the description for the channel

  • icon: the default icon for the notification, in the example application the icon is in the res folder as a mipmap, so it's adressed as @mipmap/icon_notif, iff the icon is a drawable use @drawable/icon_notif.

Request a token

To request a notification token you need to do the following things:

  1. Set a callback that will be called once the token is received correctly from APNS/FCM

MBPush.onToken = (token) {
    print("Token retrieved: $token");
}
  1. Request the token using MPush:

MBPush.requestToken();

Register to topics

Once you have a notification token you can register this device to push notifications and register to topics:

MBPush.onToken = (token) async {
  print("Token received $token");
  await MBPush.registerDevice(token).catchError(
    (error) => print(error),
  );
  await MBPush.registerToTopic(MPTopic(code: 'Topic')).catchError(
    (error) => print(error),
  );
  print('Registered');
};

The topic are instances of the MPTopic class which has 3 properties:

  • code: the id of the topic

  • [Optional] title: the readable title of the topic that will be displayed in the dashboard, if this is not set it will be equal to code.

  • [Optional] single: if this topic represents a single device or a group of devices, by default false.

MBurger topics

MBurger has 2 default topics that you should use in order to guarantee the correct functionality of the engagement platform:

  • MBMessages.projectPushTopic(): this topic represents all devices registred to push notifications for this project

  • MBMessages.devicePushTopic(): this topic represents the current device

await MBPush.registerToTopics(
  [
    await MBMessages.projectPushTopic(),
    await MBMessages.devicePushTopic(),
    MPTopic(code: 'Topic'),
  ],
);

Launch notification

If the application was launched from a notification you can retrieve the data of the notification like this, this will be null if the application was launched normally:

Map<String, dynamic> launchNotification = await MBPush.launchNotification();
print(launchNotification);
🔷
MPush documentation