Notification Center 4.x.x

pub 3.2.0

Installation

To add the MoEngage Inbox SDK to your application, edit your application's pubspec.yaml file and add the below dependency to it:

pubspec.yaml
dependencies:
 moengage_inbox: $latestVersion

Run flutter packages get to install the SDK.

Note: This plugin is dependent on moengage_flutter plugin. Make sure you have installed the moengage_flutter plugin as well. Refer to the doc for the same.

Android Installation

Download

Once you install the Flutter Plugin add MoEngage's native Android SDK dependency to the Android project of your application.
Navigate to android --> app --> build.gradle. Add the MoEngage Android SDK's dependency in the dependencies block

build.gradle
dependencies {
  implementation fileTree(dir: 'libs', include: ['*.jar'])
  implementation("com.moengage:inbox-core:$sdkVersion")
}

where $sdkVersion should be replaced by the latest version of the MoEngage SDK.

iOS Installation

In the case of iOS, the native dependency is part of the core SDK itself, so there is no need to include any additional dependency for supporting Notification Center.

warning

Warning

Make sure to configure AppGroup ID in App Target and Set up Notification Service Extension in your iOS Project, for the SDK to save the received notifications.

Fetch Messages

To fetch all the inbox messages use fetchAllMessages() method as shown below, where you would get an instance of InboxData

Dart
import 'package:moengage_inbox/inbox_data.dart';
import 'package:moengage_inbox/inbox_message.dart';
import 'package:moengage_inbox/moengage_inbox.dart';
MoEngageInbox _moEngageInbox = MoEngageInbox();
InboxData data = await _moEngageInbox.fetchAllMessages();

InboxData Payload

InboxData will be received in the below format:

Dart
class InboxData {
  /// Native platform from which the callback was triggered.(ios/android)
  String platform;

  /// List of [InboxMessage]
  List<InboxMessage> messages;
}

class InboxMessage {
  /// internal identifier used by the SDK for storage.(Only Android)
  int id;

  /// Unique identifier for a message.
  String campaignId;

  /// Text content of the message. Instance of TextContent
  TextContent textContent;

  /// true if the message has been clicked by the user else false
  bool isClicked;

  /// Media content associated with the message.
  Media media;

  /// List of actions to be executed on click. Instances of [Action]
  List<Action> action;

  /// Tag associated with the message.
  String tag;

  /// The time in which the message was received on the device.
  ///
  /// Format - ISO-8601 yyyy-MM-dd'T'HH:mm:ss'Z'
  String receivedTime;

  /// The time at which the message expiry.
  ///
  /// Format - ISO-8601 yyyy-MM-dd'T'HH:mm:ss'Z'
  String expiry;

  /// Complete message payload. This will vary for platforms
  Map<String, dynamic> payload;
}

class Action {
  /// ActionType - navigation
  ActionType actionType;

  /// Navigation Action Instance 
  Action(this.actionType);
}

class NavigationAction extends Action {
  /// NavigationType - deepLink, richLanding, screenName
  NavigationType navigationType;

  /// Value associated with Navigation Action eg: url / screen name
  String value;

  /// Custom Key-Value Pairs associated with action
  Map<String, dynamic> kvPair;
}


class Media {
  /// Content type of the Media. (image/video/audio)
  MediaType mediaType;

  /// Url for the media content. Generally a http(s) url.
  String url;
}

Get Unclicked Message Count

To obtain the unclicked messages count from the Inbox use getUnClickedCount() method as shown below:

Dart
MoEngageInbox _moEngageInbox = MoEngageInbox();
int count = await _moEngageInbox.getUnClickedCount();

Track Message Clicks:

To track clicks on the messages inside your Inbox use trackMessageClicked() method as shown below:

Dart
MoEngageInbox _moEngageInbox = MoEngageInbox();
_moEngageInbox.trackMessageClicked(message);  //Pass the instance of InboxMessage here

Delete Message:

To delete a particular message from the list of messages use deleteMessage() method as shown below:

Dart
MoEngageInbox _moEngageInbox = MoEngageInbox();
_moEngageInbox.deleteMessage(message);  //Pass the instance of InboxMessage here

Previous

Next

Was this article helpful?
0 out of 0 found this helpful

How can we improve this article?