Skip to content

Swift Package Manager integration

Milan Parađina edited this page Sep 9, 2026 · 1 revision

Swift Package Manager Integration

Starting from plugin version 10.0.0, the iOS side of the Mobile Messaging Flutter plugin supports Swift Package Manager (SPM) as the dependency manager, in addition to the existing CocoaPods integration.

CocoaPods will still be fully supported until December 2nd, 2026, when CocoaPods Trunk is scheduled to become permanently read-only. If you are not ready to migrate, you can continue using CocoaPods and will receive all plugin updates as before. Until then, no action is required. After December 2nd, the iOS side of the plugin will only be updated with Swift Package Manager.


Background

The plugin now ships both a Package.swift manifest (for SPM, under ios/infobip_mobilemessaging/) and a .podspec (for CocoaPods, ios/infobip_mobilemessaging.podspec). Which one Flutter's tooling picks depends on whether Swift Package Manager support is enabled for your Flutter installation and whether your app's ios/ project still has a Podfile:

Configuration Dependency manager used
SPM disabled and ios/Podfile present CocoaPods
SPM enabled and Package.swift available Swift Package Manager
  • Flutter added native SPM support starting with Flutter 3.24.0. It is opt-in per Flutter installation via flutter config.
    • With Flutter v3.44.0 and above, SPM is the default dependency manager for iOS, unless explicitly disabled.
  • If a Podfile already exists in your app's ios/ folder and SPM is enabled, Flutter will keep using CocoaPods along with the available Swift Packages to avoid breaking existing projects with mixed native dependencies.
  • To completely move to SPM you need to remove the Podfile (see migration steps below), but it is not required.

Prerequisites for SPM

To use SPM you need:

  • Flutter 3.24.0 or higher
  • Xcode 16 or higher
  • iOS deployment target 15.0 or higher

Migrating from CocoaPods to SPM

1. Enable Swift Package Manager support in Flutter

flutter config --enable-swift-package-manager

This is a global Flutter tooling setting (stored in your Flutter config), not a per-project setting.

2. Update the plugin

In your pubspec.yaml, make sure you're on plugin version 10.0.0 or above:

dependencies:
  infobip_mobilemessaging: ^10.0.0 # or above

3. Fetch the dependencies:

flutter pub get

4. Ensure your deployment target is 15.0+

  • If you need to raise the minimum deployment target, set it in Xcode's Runner target build settings (IPHONEOS_DEPLOYMENT_TARGET) and set it to 15.0 or higher.

  • After changing the deployment target, run the following command from the application:

flutter build ios --config-only

5. (Optional) Remove CocoaPods artifacts

If all of your iOS dependencies already support Swift Package Manager, the legacy Cocoapods artifacts can be removed:

cd ios
rm -f Podfile Podfile.lock
rm -rf Pods
pod deintegrate
cd ..

6. Regenerate the iOS project files

flutter pub get
flutter build ios

flutter pub get regenerates ios/Flutter/ephemeral/Packages/FlutterGeneratedPluginSwiftPackage, which now references this plugin's Package.swift instead of a .podspec. flutter build (or opening the project in Xcode) triggers Xcode to resolve the SPM graph, fetching MobileMessaging and its dependencies from mobile-messaging-sdk-ios.

6. Open and modify the Runner's AppDelegate

  • Open ios/Runner.xcodeproj if only Swift Package Manager dependencies are used in the application

  • Open ios/Runner.xcworkspace if both Swift Package Manager and Cocoapods dependencies are used in the application

  • Once the project is opened, go to Runner > AppDelegate.swift where the MobileMessagingPluginApplicationDelegate is located, and change the import from MobileMessaging to infobip_mobilemessaging.

The AppDelegate.swift should now look like this:

import UIKit
import Flutter
import infobip_mobilemessaging

@main
@objc class AppDelegate: FlutterAppDelegate {
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
    MobileMessagingPluginApplicationDelegate.install()
    GeneratedPluginRegistrant.register(with: self)
    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }
}
  • After modifying the Swift file, run the project.

Rich notifications

To integrate the Notification Service Extension for Rich Notifications and better delivery reporting on iOS with Swift Package Manager, following the guide here.

WebRTCUI is opt-in

Just like the CocoaPods integration (where MobileMessaging/WebRTCUI is only added when $WebRTCUIEnabled is set in the Podfile), the SPM integration does not download or link WebRTCUI by default. To enable it, set the INFOBIP_WEBRTCUI_ENABLED environment variable to 1 (or true) in the environment that resolves the package, before running flutter pub get / flutter build ios:

export INFOBIP_WEBRTCUI_ENABLED=1
flutter build ios

Since this is read at package-manifest resolution time (not app runtime), it must be exported in the shell/CI environment — Xcode scheme "Environment Variables" don't apply. If you resolve packages by opening Runner.xcworkspace/.xcodeproj directly in Xcode's GUI, export the variable and launch Xcode from that same shell (open -a Xcode .), or run launchctl setenv INFOBIP_WEBRTCUI_ENABLED 1 and relaunch Xcode.

If you toggle the flag after the package has already been resolved, clear the cached resolution first (flutter clean, delete ios/.build/Package.resolved, or use Xcode's File > Packages > Reset Package Caches).

Staying on CocoaPods

If you are not ready to migrate, disable the SPM flag and keep the existing ios/Podfile in your project:

# disable the SPM flag
flutter config --no-enable-swift-package-manager

# fetch the dependencies
flutter pub get

# build the iOS project
flutter build ios

No changes to the plugin are needed, as the .podspec remains published and CocoaPods will continue to be used exactly as before.

The plugin will receive updates, including new features and bug fixes with the CocoaPods integration, until the official CocoaPods Trunk becomes permanently read-only. After that period, the iOS part of the plugin will receive regular updates only via Swift Package Manager.


Troubleshooting

SPM package resolution fails

Ensure you have a stable internet connection the first time Xcode resolves packages (either via flutter build ios or opening the project directly), since it needs to fetch packages from GitHub.

Module 'infobip_mobilemessaging' not found

If you are getting the error above when using the dependency in the the example (or your) application, this usually means that support for Swift Package Manager was not enabled in the Flutter configuration. Simply run the following command to enable it:

flutter config --enable-swift-package-manager

After enabling it, run the flutter build ios command again.

Deployment target error

If you are seeing the error: FlutterGeneratedPluginSwiftPackage has a lower minimum deployment target, ensure that the IPHONEOS_DEPLOYMENT_TARGET flag on the Runner target (and on the MobileMessagingNotificationServiceExtension target, if present) is set to 15.0 or higher.

If you do not want to modify the flag manually, simply run the command:

flutter build ios --config-only

Still seeing CocoaPods being used after enabling the flag

Navigate to the ios folder and run the following command:

pod deintegrate

This will remove the Pods manifests, frameworks and xcconfig files. After running the command, reopen the Runner project and run the application.

Clone this wiki locally