flutter_aepmessaging

pub package Build License

flutter_aepmessaging is a flutter plugin for the iOS and Android AEPMessaging SDK to allow for integration with Flutter applications. Functionality to enable the Messaging extension is provided entirely through Dart documented below.

Prerequisites

The Adobe Experience Platform Messaging extension has the following peer dependency, which must be installed prior to installing it:

Installation

Install instructions for this package can be found here.

Note: After you have installed the SDK, don't forget to run pod install in your ios directory to link the libraries to your Xcode project.

Usage

For more detailed information on the Messaging APIs, visit the documentation here

Importing the extension:

In your Flutter application, import the Messaging extension as follows:

import 'package:flutter_aepmessaging/flutter_aepmessaging.dart';

Initializing with SDK:

To initialize the SDK, use the following methods:

Refer to the root Readme for more information about the SDK setup.

API reference

extensionVersion

Returns the SDK version of the Messaging extension.

Syntax

static Future<String> get extensionVersion

Example

String version = await Messaging.extensionVersion;

getCachedMessages

Returns a list of messages that have currently been cached in-memory using Messaging.saveMessage()

Syntax

List<Message> messages = await Messaging.getCachedMessages();

refreshInAppMessages

This API retrieves the Experience Cloud ID (ECID) that was generated when the app was initially launched. This ID is preserved between app upgrades, is saved and restored during the standard application backup process, and is removed at uninstall.

Syntax

static Future<void> refreshInAppMessages

Example

await Messaging.refreshInAppMessages();

Handling In App Messages using Message Object

Note: In order to use the methods defined in the Message class, use getCachedMessages to retrieve the messages that have been cached in-memory, and then use the Message objects returned.

The Message object passed to the MessagingDelegate contains the following functions to handle a message:

show

Signals to the UIService that the message should be displayed.

Syntax

show()

Example

Message message
message.show()

dismiss

Signals to the UIService that the message should be dismissed.

Syntax

dismiss(((suppressAutoTrack: ?boolean) = false))

Example

Message message
message.dismiss(true)

track

Generates an Edge Event for the provided interaction and event type.

Syntax

track(String interaction, MessagingEdgeEventType eventType)

Example

Message message;
message.track("sample text", MessagingEdgeEventType.IN_APP_DISMISS)

setAutoTrack

Enables/Disables auto-tracking for message events.

Syntax

setAutoTrack(Bool autoTrack)

Example

Message message;
message.setAutoTrack(true)

clear

Clears the reference to the in-memory cached Message object. This function must be called if a message was saved by calling shouldSaveMessage but no longer needed. Failure to call this function leads to memory leaks.

Syntax

clear()

Example

Message message
message.clear()

Push Notification Setup

Handling push notifications must be done in native (Android/iOS) code for the Flutter app. To configure push notifications in the native project, follow the instructions provided for their respective platforms:

Push Messaging APIs usage

The AEPMessaging extension's push messaging APIs must be called from the native Android/iOS project of Flutter app.

iOS API usage
Android API usage

In Android, MessagingPushPayload can be used for getting the notification attributes like title, body, and action. These are useful for push notification creation.

Tests

Run:

flutter test

Contributing

See CONTRIBUTING

License

See LICENSE

Libraries

flutter_aepmessaging
Copyright 2023 Adobe. All rights reserved. This file is licensed to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.