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.
The Adobe Experience Platform Messaging extension has the following peer dependency, which must be installed prior to installing it:
Install instructions for this package can be found here.
Note: After you have installed the SDK, don't forget to run
pod install
in yourios
directory to link the libraries to your Xcode project.
Run:
flutter test
For more detailed information on the Messaging APIs, visit the documentation here
Note: It is required to initialize the SDK via native code inside your AppDelegate (iOS) and MainApplication class (Android).
As part of the initialization code, make sure that you set the SDK wrapper type to Flutter
before you start the SDK.
Refer to the Initialization section of the root README for more information about initializing the SDK.
Initialization Example
iOS
// AppDelegate.h
@import AEPCore;
@import AEPEdge;
@import AEPEdgeIdentity;
@import AEPMessaging;
...
@implementation AppDelegate
// AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[AEPMobileCore setWrapperType:AEPWrapperTypeFlutter];
// TODO: Set up the preferred Environment File ID from your mobile property configured in Data Collection UI
NSString* ENVIRONMENT_FILE_ID = @'YOUR-APP-ID';
NSArray *extensionsToRegister = @[AEPMessaging.class,
AEPMobileEdge.class,
AEPMobileEdgeIdentity.class
];
[AEPMobileCore registerExtensions:extensionsToRegister completion:^{
[AEPMobileCore configureWithAppId: ENVIRONMENT_FILE_ID];
}];
return YES;
}
Android
import com.adobe.marketing.mobile.MobileCore;
import com.adobe.marketing.mobile.Edge;
import com.adobe.marketing.mobile.messaging.Messaging;
...
import io.flutter.app.FlutterApplication;
...
public class MainApplication extends FlutterApplication {
...
// TODO: Set up the preferred Environment File ID from your mobile property configured in Data Collection UI
private final String ENVIRONMENT_FILE_ID = "YOUR-APP-ID";
@Override
public void onCreate() {
super.onCreate();
List<Class<? extends Extension>> extensions = Arrays.asList(
Edge.EXTENSION,
EdgeIdentity.EXTENSION,
Messaging.EXTENSION
);
MobileCore.registerExtensions(extensions, o -> MobileCore.configureWithAppID(ENVIRONMENT_FILE_ID));
}
}
In your Flutter application, import the Messaging extension as follows:
import 'package:flutter_aepmessaging/flutter_aepmessaging.dart';
Returns the SDK version of the Messaging extension.
Syntax
static Future<String> get extensionVersion
Example
String version = await Messaging.extensionVersion;
Returns a list of messages that have currently been cached in-memory using Messaging.saveMessage()
Syntax
List<Message> messages = await Messaging.getCachedMessages();
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();
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:
Signals to the UIService
that the message should be displayed.
Syntax
show()
Example
Message message
message.show()
Signals to the UIService
that the message should be dismissed.
Syntax
dismiss(((suppressAutoTrack: ?boolean) = false))
Example
Message message
message.dismiss(true)
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)
Enables/Disables auto-tracking for message events.
Syntax
setAutoTrack(Bool autoTrack)
Example
Message message;
message.setAutoTrack(true)
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()
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:
The AEPMessaging extension's push messaging APIs must be called from the native Android/iOS project of Flutter app.
In Android, MessagingPushPayload can be used for getting the notification attributes like title, body, and action. These are useful for push notification creation.
See CONTRIBUTING
See LICENSE