Add the Flutter plug-in to your app

Overview

To start configuring basic mobile app messaging in Flutter projects for iOS and Android apps, create an example app in Flutter and then configure and build your Android and iOS apps. After configuring basic mobile app messages, you can configure advanced mobile app messaging features.

🚧

Warning:

When Acoustic Mobile App Messaging stores data that you send, the data is not encrypted; therefore, it is recommended that you do not transmit sensitive information in the inbox, in-app, and mobile app messages. The data is not encrypted in our databases or log files or when stored on the device. If you must transmit sensitive information, encrypt the data before sending it and decrypt the data in memory on the device.

Before you begin

Set up the appropriate environment. For more information, see Set up an editor.

πŸ“˜

Note:

The Acoustic Flutter SDK supports Flutter SDK version >=2.12.0 <3.0.0. Verify the correct Flutter SDK is installed when setting up your environment.

Create a Flutter application

Use the flutter create command to create a new project:

$ flutter create myapp
$ cd myapp

You can also pass other arguments to the flutter create command, such as the project name (pubspec.yml), the organization name, or specify the programming language used for the native platform. For more information, see Create the app.
Example:

$ flutter create --project-name myapp --org dev. Flutter --android-language java --ios-language objc myapp
$ cd myapp

πŸ“˜

Note:

To add Flutter to an existing application, see Add Flutter to existing app.

Install Acoustic Flutter plug-in

  1. Download the Acoustic Flutter plug-in.
  2. Add your application to the Root/Applications directory in the Flutter plug-in. The Acoustic Flutter plug-in repo is structured as follows:
-Root
 -Applications
  -Sample
  -<add your applications>
 -Plugins
  -<all the plug-ins here>

The Acoustic Flutter plug-in is packaged as separate plug-ins with various peer dependencies. The peer dependencies are listed in the pubspec.yaml file for the respective plug-in.

Link the plug-ins

To link the plug-ins to your application, you can add them as dependencies in your app's pubspec.yaml file as follows:

🚧

Note:

If you are using VSCode, it automatically runs the flutter pub get command which installs the plug-ins to your app.

If you are not using VSCode, you must manually run the flutter pub get command after adding the new dependencies.

dependencies:
  flutter:
    sdk: flutter
  flutter_acoustic_mobile_push:
    path: ../../plugins/flutter_acoustic_mobile_push
  flutter_acoustic_mobile_push_inbox:
    path: ../../plugins/flutter_acoustic_mobile_push_inbox
  flutter_acoustic_mobile_push_beacon:
    path: ../../plugins/flutter_acoustic_mobile_push_beacon
  flutter_acoustic_mobile_push_geofence:
    path: ../../plugins/flutter_acoustic_mobile_push_geofence
  flutter_acoustic_mobile_push_inapp:
    path: ../../plugins/flutter_acoustic_mobile_push_inapp
  flutter_acoustic_mobile_push_location:
    path: ../../plugins/flutter_acoustic_mobile_push_location

πŸ“˜

Note:

The location plug-in is required if you use the beacon or geofence plug-ins.

πŸ“˜

Note:

The example paths to the plug-ins assume you placed the app in the same directory as the sample app. If you place your app in a different directory, update the paths accordingly.

Set up your iOS project

When creating a new Flutter project, the iOS platform's default version is 9.0. The Acoustic Flutter plugin requires a minimum version of 12.1.

Update the pod file

To update the iOS platform:

  1. Open the podfile in your app's iOS directory.
  2. Replace # platform :ios, '9.0' with platform :ios, '12.1'.
  3. Change into the iOS directory cd ios.
  4. Install the pods using the pod install command.

Use the plug-ins in your app

You can import the .dart files directly into your application:

import 'package:flutter_acoustic_mobile_push/flutter_acoustic_sdk_push.dart';
import 'package:flutter_acoustic_mobile_push_inbox/inbox/messages/inbox_messages.dart';
import 'package:flutter_acoustic_mobile_push_inapp/flutter_acoustic_mobile_push_inapp.dart';
import 'package:flutter_acoustic_mobile_push_location/location.dart';

For more information about using each plug-in, see examples provided in the sample in the applications/sample/ folder.

Update the project version

To update the project version:

  1. Open your .xcworkspace file.
  2. Select your main app target.
  3. In the General tab, set the Minimum Deployments version to 12.1.

Integrate the SDK into your app

  1. Download the MceConfig file and add it to all your application project's targets. For more information about MceConfig, see Configuration (MceConfig.json).
  2. Set your team and provisioning profile in the Signing and Capabilities tab. You must complete this step before the app has permission to get the APNs deviceToken.
  3. For the pod target and the app target, go to the Build Settings tab and set Set Build Active Architectures Only to No. You must set it to No for both Debug and Release.
  4. Set Push Notification capability in Target Capabilities.
  5. Add App Group capability to your main application target. Be sure to create and check the checkmark for the App Group in the interface.
  6. Add the Keychain Sharing capability to your main application target. Be sure to add a Keychain Group value to the list.
  7. Turn on location updates if you want to use locations or beacons with your app:
  • Go to the Capabilities tab for your target > Background Modes section.
  • Select Location updates. For more information, see Device Location Awareness (DLA Device Location Awareness (DLA).

Automated integration

The iOS SDK is compatible with the Swift programming language. Any version of the SDK before v3.6.10 does not work with Swift Application Delegates. You can use a workaround by using an Objective-C delegate class. Usage of the SDK from Swift is demonstrated in the Swift sample project starting with V3.6.10.

  1. The automatic integration method requires a main.swift file to be created in the project. It should contain the following:
import UIKit
import AcousticMobilePush

let argv = UnsafeMutableRawPointer(CommandLine.unsafeArgv).bindMemory(to: UnsafeMutablePointer<Int8>.self, capacity: Int(CommandLine.argc))
let _ = UIApplicationMain(CommandLine.argc, CommandLine.unsafeArgv, nil, NSStringFromClass(MCEAppDelegate.self) )
  1. In order for Swift to use the classes in the SDK, you must import the framework at the top of the Swift files that use it. For more information, see Apple Developer documentation.
import AcousticMobilePush

πŸ“˜

Note:

When you use Swift, prefix the package name to the appDelegateClass in the MCEconfig file.

{
  "appDelegateClass": "Sample.AppDelegate"
  ... // Rest of MceConfig.json file
}
  1. Add the following import directive to the top of the AppDelegate.
import UserNotifications
  1. Add didFinishLaunchingWithOptions to the application method in your AppDelegate class. This code sets the notification type to badge, sound, and alert. You can remove the unwanted notification types from each OS support level declaration.
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool {
        application.registerForRemoteNotifications()

    // iOS 10+ Example static action category:
    let acceptAction = UNNotificationAction(identifier: "Accept", title: "Accept", options: [.foreground])
    let rejectAction = UNNotificationAction(identifier: "Reject", title: "Reject", options: [.destructive])
    let category = UNNotificationCategory(identifier: "example", actions: [acceptAction, rejectAction], intentIdentifiers: [], options: [.customDismissAction])
    
    var categories = Set()
    categories.insert(category)
    
    // iOS 10+ Push Message Registration
    let center = UNUserNotificationCenter.current()
    center.requestAuthorization(options: [.alert, .sound, .carPlay, .badge], completionHandler: { (granted, error) in
        if let error = error {
            print("Could not request authorization from APNS \(error.localizedDescription)")
        }
        center.setNotificationCategories(categories)
    })
    
    return true
}

For more information about integrating the iOS SDK to your app, see Add the iOS SDK to your app

Update the SDK configuration

  1. Open the MceConfig.json file.
  2. Swift requires your class to be in a namespace. For example, update the appDelegateClass value to SwiftSample.AppDelegate in the Swift sample app.
  3. Update the dev and prod entries in the appKey section to match the App Keys created in the web portal.
  • The dev entry is used when you run the app from Xcode with a development provisioning profile. The prod entry is used when you run the app with an App Store, Enterprise, or AdHoc provisioning profile.
  • If you do not have a production App Key, use apXXXXXXXX for the prod entry.
  1. Update the baseUrl entry to match the server for your App Key. The baseURL was provided when your account was provisioned for mobile app messaging.
  2. If you are not using Geofences or iBeacons, you can remove the location entry and all its children.
  3. If you are using iBeacons, update the UUID in the iBeacon section of the location entry. The UUID should match the UUID for your iBeacons.

For more information, see Configuration (MceConfig.json).

Now you can compile and run the app to start communication with the Acoustic servers. Use the verbose logs in the MceConfig.json file to debug.

Customize push notifications

Push notifications are accessed through a notification channel. You can customize the push notifications by customizing the notification channel function. To access the function:

  1. Go to the root directory of the project > plugins folder.
  2. Go to flutter_acoustic_mobile_push > android >src >main >kotlin > co > acoustic > flutter > sdk > flutter_acoustic_mobile_push and open the MainApplication.kt file.
  3. In the MainApplication.kt file, find the following code:
private fun createNotificationChannel() {

The createNotificationChannel function adds the functionality for push notifications.

  1. Customize this function to customize the push notifications.

Did this page help you?