flutter_aepmessaging
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 yourios
directory to link the libraries to your Xcode project.
Tests
Run:
flutter test
Usage
For more detailed information on the Messaging APIs, visit the documentation here
Registering the extension with AEPCore:
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));
}
}
Importing the extension
In your Flutter application, import the Messaging extension as follows:
import 'package:flutter_aepmessaging/flutter_aepmessaging.dart';
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.
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.