Mobile Messaging SDK plugin for Flutter

Mobile Messaging SDK is designed and developed to easily enable push notification channel in your mobile application. In almost no time of implementation you get push notification in your application and access to the features of Infobip IP Messaging Platform. The document describes plugin integration steps for your Flutter project.

Requirements

  • Flutter:

    • If using CocoaPods: 3.16.0+
    • If using Swift Package Manager (SPM): 3.24.0+
  • For iOS project:

    • Xcode 16.x
    • Minimum deployment target 15.0
    • CocoaPods 1.16.2
  • For Android project:

    • Android Studio
    • Supported API Levels: 23 (Android 6.0 - Marshmallow) - 37 (Android 17)

Quick start guide

This guide is designed to get you up and running with Mobile Messaging SDK plugin for Flutter

  1. Make sure to setup application at the Infobip portal, if you haven't already.

  2. Add MobileMessaging plugin by running:

$ pub get infobip_mobilemessaging
  1. It will add it to dependencies at pubspec.yaml:
dependencies:
  infobip_mobilemessaging: '^10.0.0'

  1. Run flutter pub get to install plugin

  2. Configure platforms

    • iOS

      The plugin ships both a CocoaPods podspec and a Swift Package Manager manifest, so your app can integrate it with either dependency manager.

      Dependency manager setup

      CocoaPods
      1. Update the ios/Podfile with iOS deployment target platform 15.0 - platform :ios, '15.0' if needed, and perform in Terminal cd ios && pod install
      Swift Package Manager
      1. Make sure your project uses Flutter 3.24+ with Swift Package Manager support enabled. To enable SPM, run the following command:
      flutter config --enable-swift-package-manager
      
      1. Run flutter pub get - Flutter reads the plugin's Package.swift and wires it into FlutterGeneratedPluginSwiftPackage automatically. No manual Xcode project changes are required for the main app target.
      2. Set the iOS deployment target to 15.0.
      1. Import MobileMessaging and add MobileMessagingPluginApplicationDelegate.install() into <ProjectName>/ios/Runner/AppDelegate.swift (this is required for OS callbacks such as didRegisterForRemoteNotifications to be intercepted by native MobileMessaging SDK).
      • If using SPM, import the infobip_mobilemessaging dependency.
      • If using CocoaPods, import the MobileMessaging depdendency. The AppDelegate should now look like the following:
             import UIKit
             import Flutter
             // if using Swift Package Manager, import the infobip_mobilemessaging dependency
             import infobip_mobilemessaging
             // if using CocoaPods, import the MobileMessaging dependency
             import MobileMessaging 
      
             @main
             @objc class AppDelegate: FlutterAppDelegate {
               override func application(
                  _ application: UIApplication,
                  didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
                ) -> Bool {
                   ...
                   MobileMessagingPluginApplicationDelegate.install()
                   ...
                }
              }
             ...
      

      Notice

      An Objective-C AppDelegate.m is only supported with the CocoaPods integration:

             ...
             @import MobileMessaging;
      
             @implementation AppDelegate
      
             - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
             {
                 ...
                 [MobileMessagingPluginApplicationDelegate install];
                 ...
             }
             ...
      

      Swift Package Manager integration requires a Swift AppDelegate.swift.

      1. Configure your project to support Push Notification as described in item 2 of iOS integration quick start guide
      2. Integrate Notification Service Extension into your app in order to obtain:
        • more accurate processing of messages and delivery stats
        • support of rich notifications on the lock screen
    • Android

      1. Add 'com.google.gms:google-services' to android/build.gradle file
      buildscript {
         ...
         dependencies {
             ...
            //Google Services gradle plugin
            classpath 'com.google.gms:google-services:4.4.1'
         }
      }
      
      1. Add apply plugin: 'com.google.gms.google-services' at the end of your android/app/build.gradle in order to apply Google Services Gradle Plugin
      2. Setup Firebase for your project and add a Firebase configuration file (google-services.json) to the app as described in Firebase documentation. Usually it needs to be added into android/app folder.

      Notice

      If you want to provide the Firebase configuration differently, check Applying Firebase configuration

      Notice

      Starting from Android 13, Google requires to ask user for notification permission. Follow this guide to make a permission request.

  3. Use plugin in your main.dart file:

    import 'package:infobip_mobilemessaging/infobip_mobilemessaging.dart';
    import 'package:infobip_mobilemessaging/models/configurations/configuration.dart' as mmconf;
    import 'package:infobip_mobilemessaging/models/library_event.dart';
    
    ...
    
        await InfobipMobilemessaging.init(mmconf.Configuration(
          applicationCode: '<Your app code>',
          iosSettings: mmconf.IOSSettings(
            notificationTypes: ['alert', 'badge', 'sound'],
            logging: true,
          ),
          androidSettings: mmconf.AndroidSettings(
            multipleNotifications: true,
          ),  
        ));
    
        InfobipMobilemessaging.on(LibraryEvent.messageReceived, (Message event) => {
           print('Callback. messageReceived event,  message text: ${event.body}')
        });
    
    ...
    
    

More details on SDK features and FAQ you can find on Wiki


NEXT STEPS: Users and installations