Set up push notifications
Our Flutter SDK supports push notifications over FCM—including rich push messages with links and images. This page helps you add push support to your app.
How it works
If you’ve followed our getting started instructions, you’re already set up to send push notifications to your Android audience. But you’ll need to add a bit of code to support your iOS users.
Remember that a device/user can’t receive a push notification until you:
- (iOS) Register a device token for the device; code samples on this page help you do that.
- Identify a person. This associates a token with the person; you can’t send push notifications to a device until you identify the recipient.
- (Both iOS and Android) Check for notification permissions. If your app user doesn’t grant permission, notifications will not appear in the system tray.
- (Optional) Set up your app to report push metrics back to Customer.io.
Set up push for Android
If you followed our Getting Started instructions, you’re already set up to send push notifications to Android devices. You just need to set up iOS push support in your app.
Next, you can set up deep links if you want your notifications to link into your app.
Set or change your push icon
You’ll set the icon that appears on push notifications as a part of the AndroidManifest.xml file in your app’s android folder. If your icon appears in the wrong size, or if you want to change the standard icon that appears with your push notifications, you’ll need to update your app’s manifest.
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="@drawable/ic_notification" />
<meta-data
android:name="com.google.firebase.messaging.default_notification_color"
android:resource="@color/colorNotificationIcon" />Set up push for iOS
You’ll need to add some additional code to support push notifications for iOS. You’ll need to add push capabilities in XCode and integrate push capabilities in your app.
Add push capabilities in Xcode
Before you can work with push notifications, you need to add Push Notification capabilities to your project in XCode.
-
In your Flutter project, go to the
iosfolder and open<yourAppName>.xcworkspace. -
Select your project. Under Targets, select your main app.
-
Click the Signing & Capabilities tab and click Capability.
-
Add Push Notifications to your app.
-
Select File > New > Target.
-
Select Notification Service Extension and click Next.
-
You should see a window such as this:
You can leave many of the options in this window as their defaults, but you should:
- Enter a product name, like NotificationServiceExtension (which we use in our examples on this page)
- Confirm that your main app is selected in the Embed in Application drop-down menu
When you’re done, click Finish.
-
When presented with the dialog below, click Cancel. This will help Xcode continue debugging your app and not just the extension you just added.
Now you have another target in your project navigator named NotificationServiceExtension. We’ll configure this extension when we Integrate Push Notifications in the following section.
Integrate push capabilities in your app
Install dependencies
You can install iOS dependencies using Swift Package Manager (SPM), which Flutter turns on by default, or CocoaPods.
Swift Package Manager (SPM)
Before you start, make sure you meet the following requirements:
- Flutter 3.44+
- Xcode 16.0+
firebase_core: ^3.5.0andfirebase_messaging: ^15.2.0or higher (older versions don’t support SPM). We recommend at leastfirebase_core: ^4.6.0andfirebase_messaging: ^16.1.3.
-
Enable SPM (if not already enabled). Flutter 3.44 and later turn SPM on by default. If your
pubspec.yamlsetsenable-swift-package-manager: false, change it totrue, because that setting overridesflutter config. Then runflutter pub get. The Customer.io SDK is automatically resolved - no manual Xcode setup needed for the main app. -
Update your Podfile. Remove any
customer_iopod lines from yourRunnertarget inios/Podfile. With SPM enabled, Flutter builds the plugin from its Swift package, so these lines no longer change it. Acustomer_io/fcmline still installs FirebaseMessaging from CocoaPods, which gives your app a second copy of Firebase next to FlutterFire’s:RUBYpod 'customer_io/fcm', :path => ... pod 'customer_io/location', :path => ...For each module you used a subspec for, set its key in
android/gradle.propertiesinstead. See Upgrade from 5.x to 6.0.0. -
Set up Rich Push (NSE). Add the Customer.io push package to your Notification Service Extension in Xcode:
- Open
ios/Runner.xcworkspacein Xcode, select your project, and go to the Package Dependencies tab. If the list already hascustomerio-ios, for example for a Live Activity widget, set its dependency rule to Up to Next Major Version from5.0.0(see Exact versions in your Xcode project). Otherwise, click +, enterhttps://github.com/customerio/customerio-ios.git, set the dependency rule to Up to Next Major Version from5.0.0, and click Add Package. - Add the MessagingPushFCM product to your
NotificationServiceExtensiontarget only. Ifcustomerio-ioswas already in the list, select the extension target, and click + under General > Frameworks and Libraries. The plugin already adds the SDK to your app.
The plugin sets the exact iOS SDK version, and Xcode resolves your extension to that same version. Your extension doesn’t need Firebase or Flutter.
If your extension already gets the push module from
pod 'customer_io_richpush/fcm'in yourios/Podfile, you can keep that setup instead. - Open
The plugin automatically includes the following modules via SPM:
| Module | Purpose |
|---|---|
| DataPipelines | Core SDK |
| MessagingInApp | In-app messaging |
| MessagingInbox | Notification inbox |
| MessagingPushFCM | Push notifications over FCM |
| CioFirebaseWrapper | Connects push notifications to the Firebase Messaging that your app gets from FlutterFire |
The Location module is not included by default. To include it, set customerio_location_enabled=true in your android/gradle.properties file. This flag controls both Android and iOS. See Location tracking for details.
With Swift Package Manager on, the plugin’s Swift package reads the customerio_..._enabled keys from android/gradle.properties when Xcode loads the package. Use version 6.0.2 or later of the plugin, which finds that file wherever your build starts. Earlier versions can miss the file, and then Xcode builds your app without these modules and doesn’t show an error.
Swift Package Manager caches what the plugin’s package reads, and doesn’t notice when you change one of these keys. After you change a key, delete the cache before you build again. It isn’t enough to run the flutter clean command or delete Xcode’s DerivedData folder.
rm -rf ~/Library/Caches/org.swift.swiftpm/manifestsCocoaPods
-
Turn off SPM for your app in
pubspec.yaml, and then runflutter pub get. This setting applies on every machine that builds your app, including CI:YAMLflutter: config: enable-swift-package-manager: false -
Open the file
ios/Podfileand make the following modifications:RUBYtarget 'Runner' do # Look for the main app target. # Required by FCM push notification service use_frameworks! # Make all file modifications after these lines: flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__)) # Add the following line to add the Customer.io native dependency: pod 'customer_io/fcm', :path => '.symlinks/plugins/customer_io/ios' end # Next, copy and paste the code below to the bottom of your Podfile: target 'NotificationServiceExtension' do use_frameworks! pod 'customer_io_richpush/fcm', :path => '.symlinks/plugins/customer_io/ios' endThe
customer_io/fcmsubspec installs the FirebaseMessaging pod. If your app gets Firebase another way, like through SPM, usepod 'customer_io/fcm-core', :path => '.symlinks/plugins/customer_io/ios'instead. It adds Customer.io’s FCM support without a second copy of Firebase. -
From your
iosfolder, runpod install. You can also letflutter build iosrun it for you.The
customer_ioandcustomer_io_richpushpods don’t install any Customer.io pods. Xcode downloads the Customer.io iOS SDK from GitHub as a Swift package when it builds your app, so your build machines need access to github.com.
Configure your app
-
Update your
AppDelegate.swiftfile to handle push notifications:SWIFTimport UIKit import Flutter import CioMessagingPushFCM import CioFirebaseWrapper import FirebaseMessaging import FirebaseCore @main class AppDelegateWithCioIntegration: CioAppDelegateWrapper<AppDelegate> {} class AppDelegate: FlutterAppDelegate { override func application( _ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? ) -> Bool { GeneratedPluginRegistrant.register(with: self) // Depending on how you install Firebase, // you may need to add functions to this file, like: // FirebaseApp.configure() // // Read the official Firebase docs to install Firebase correctly! MessagingPushFCM.initialize( withConfig: MessagingPushConfigBuilder() // .appGroupId("group.com.example.myapp.cio") // Optional: for reliable delivery tracking .build() ) // Add line below only if you want to have custom control over notifications being presented and processed - Customer.io will handle those automatically UNUserNotificationCenter.current().delegate = self as UNUserNotificationCenterDelegate return super.application(application, didFinishLaunchingWithOptions: launchOptions) } override func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) { super.application(application, didRegisterForRemoteNotificationsWithDeviceToken: deviceToken) Messaging.messaging().apnsToken = deviceToken } } -
Open your
NotificationService.swiftfile in Xcode and modify it with the highlighted changes below:SWIFTimport CioMessagingPushFCM import UserNotifications class NotificationService: UNNotificationServiceExtension { override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) { MessagingPushFCM.initializeForExtension( withConfig: MessagingPushConfigBuilder(cdpApiKey: "YourCdpApiKey") // Optional: set your Customer.io account region (.US or .EU). Default: US .region(.US) // .appGroupId("group.com.example.myapp.cio") // Optional: for reliable delivery tracking .build() ) // Returns false for a push that Customer.io didn't send, without calling // contentHandler. Deliver that push unchanged so iOS shows it right away. if !MessagingPush.shared.didReceive(request, withContentHandler: contentHandler) { contentHandler(request.content) } } override func serviceExtensionTimeWillExpire() { MessagingPush.shared.serviceExtensionTimeWillExpire() } }
Now you can send yourself push notifications with images and deep links to test your implementation. Use a physical device for production APNs or device-specific behavior. For sandbox APNs, an iOS 16 or newer Simulator on macOS 13 or newer can receive remote notifications when its physical Mac has Apple silicon or an Apple T2 Security Chip. A simulator inside a virtualized macOS runner may not receive an APNs token.
Adopt UIScene (iOS 27)
The AppDelegate.swift setup above is the no-change path. If your app keeps the
AppDelegate-only lifecycle, you don’t need to do anything else here.
Follow the steps below only when your app adopts iOS’s UIScene lifecycle or you build with
Xcode 27.
Flutter owns the framework migration. Follow Flutter’s official UIScene adoption guide. Flutter only auto-migrates an unmodified template AppDelegate. Customer.io setup customizes that file, so follow Flutter’s manual migration steps. The rest of this section describes the Customer.io-specific result. For the full cross-platform walkthrough, see the iOS 27 UIScene migration guide.
After migration, your iOS host keeps CioAppDelegateWrapper as the application delegate, and the
wrapped AppDelegate conforms to FlutterImplicitEngineDelegate. Move GeneratedPluginRegistrant
registration out of didFinishLaunchingWithOptions and into didInitializeImplicitFlutterEngine:
import UIKit
import Flutter
import CioMessagingPushFCM
import CioFirebaseWrapper
import FirebaseMessaging
import FirebaseCore
@main
class AppDelegateWithCioIntegration: CioAppDelegateWrapper<AppDelegate> {}
@objc class AppDelegate: FlutterAppDelegate, FlutterImplicitEngineDelegate {
// Register your Flutter plugins here, instead of in didFinishLaunchingWithOptions.
func didInitializeImplicitFlutterEngine(_ engineBridge: FlutterImplicitEngineBridge) {
GeneratedPluginRegistrant.register(with: engineBridge.pluginRegistry)
}
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
// Customer.io init, APNs, and notification handling stay at the application level.
// FirebaseApp.configure()
MessagingPushFCM.initialize(
withConfig: MessagingPushConfigBuilder()
// .appGroupId("group.com.example.myapp.cio") // Optional: reliable delivery tracking
.build()
)
UNUserNotificationCenter.current().delegate = self as UNUserNotificationCenterDelegate
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
override func application(_ application: UIApplication,
didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
super.application(application, didRegisterForRemoteNotificationsWithDeviceToken: deviceToken)
Messaging.messaging().apnsToken = deviceToken
}
}Use FlutterSceneDelegate directly as your scene delegate. Add this standard single-scene
UIApplicationSceneManifest manually:
<key>UIApplicationSceneManifest</key>
<dict>
<key>UIApplicationSupportsMultipleScenes</key>
<false/>
<key>UISceneConfigurations</key>
<dict>
<key>UIWindowSceneSessionRoleApplication</key>
<array>
<dict>
<key>UISceneClassName</key>
<string>UIWindowScene</string>
<key>UISceneDelegateClassName</key>
<string>FlutterSceneDelegate</string>
<key>UISceneConfigurationName</key>
<string>flutter</string>
<key>UISceneStoryboardFile</key>
<string>Main</string>
</dict>
</array>
</dict>
</dict>If you need a custom scene delegate, subclass FlutterSceneDelegate:
import Flutter
import UIKit
class SceneDelegate: FlutterSceneDelegate {
}Then change UISceneDelegateClassName in the manifest to
$(PRODUCT_MODULE_NAME).SceneDelegate. If you write a custom scene delegate that does not
subclass FlutterSceneDelegate, it must conform to Flutter’s FlutterSceneLifeCycleProvider and
forward every scene lifecycle callback to Flutter. Point UISceneDelegateClassName at your class
in that case too.
With the standard scene manifest in place and Flutter deep linking enabled, Customer.io push and in-app destinations route through Flutter automatically. See Deep links for the routing details.
Sound in push notifications (iOS Only)
When you send a push notification to iOS devices that uses our SDK, you can opt to send the Default system sound or no sound at all. If your audience’s phone is set to vibrate, or they’ve disabled sound permissions for your app, the Default setting will cause the device to vibrate rather than playing a sound.
In most cases, you should use the Default sound setting to make sure your audience hears (or feels) your message. But, before you send sound, you should understand:
- Your app needs permission from your users to play sounds. This is done by your app, not our SDKs. Here’s an example from our iOS sample app showing how to request sound permissions.
- iOS users can go into System Settings and disable sound permissions for your app. Enabling the Default setting doesn’t guarantee that your audience hears a sound when your message is delivered!
Display push notifications in the foreground (iOS)
By default, iOS doesn’t display push notifications when your app is in the foreground. The showPushAppInForeground configuration flag (set to true by default) tells iOS to display notifications even when your app is active.
MessagingPushFCM.initialize(
withConfig: MessagingPushConfigBuilder()
.showPushAppInForeground(true)
.build()
)If your app also uses FlutterFire’s firebase_messaging package, FlutterFire’s foreground presentation options take precedence over showPushAppInForeground. FlutterFire hides foreground notifications by default. To show Customer.io notifications while your app is in the foreground, call setForegroundNotificationPresentationOptions after you initialize Firebase:
await FirebaseMessaging.instance.setForegroundNotificationPresentationOptions(
alert: true,
badge: true,
sound: true,
);Implement the notification center delegate for more control
For more granular control over foreground notification behavior, you can implement the userNotificationCenter(_:willPresent:withCompletionHandler:) method in your AppDelegate.swift file. This native implementation takes precedence over the showPushAppInForeground configuration flag.
This method lets you inspect the notification content and decide whether to display it, and choose which presentation options to use (banner, list, badge, sound, or any combination).
Add this method to the AppDelegate class you set up in the integration step above:
override func userNotificationCenter(
_ center: UNUserNotificationCenter,
willPresent notification: UNNotification,
withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void
) {
// Show notifications in foreground with banner, list, badge, and sound
completionHandler([.banner, .list, .badge, .sound])
// Or return empty array if you do NOT want notifications shown in foreground
// completionHandler([])
}Test your implementation
After you set up rich push, you should test your implementation. Below, we show the payload structure we use for iOS and Android. In general, you can use our regular rich push editor; it’s set up to send messages using the JSON structure we outline below.
If you want to fashion your own payload, you can use our custom payload.
iOS FCM payload
{
"message": {
"apns": {
"payload": {
"aps": {
// basic iOS message and options go here
"mutable-content": 1,
"alert": {
"title": "string", //(optional) The title of the notification.
"body": "string" //(optional) The message you want to send.
}
},
"CIO": {
"push": {
"link": "string", //generally a deep link, i.e. my-app://... or https://yourwebsite.com/...
"image": "string" //HTTPS URL of your image, including file extension
}
}
},
"headers": {
// (optional) headers to send to the Apple Push Notification Service.
"apns-priority": 10
}
}
}
}- The base object for all FCM payloads.
- Defines a payload for iOS devices sent through Firebase Cloud Messaging (FCM).
- Contains a push payload.
- A push payload intended for an iOS device.
- Contains properties interpreted by the Customer.io iOS SDK.
- Custom key-value pairs *any typeAdditional properties that you've set up your app to interpret outside of the Customer.io SDK.
- headersobjectHeaders defined by Apple's payload reference that you want to pass through FCM.
Android payload
{
"message": {
"data": {
"title": "string", //(optional) The title of the notification.
"body": "string", //The message you want to send.
"image": "string", //https URL to an image you want to include in the notification
"link": "string" //Deep link in the format remote-habits://deep?message=hello&message2=world
}
}
}- The parent object for all push payloads.
- Contains all properties interpreted by the SDK.
- bodystringThe body of your push notification.
- imagestringThe URL of an HTTPS image that you want to use for your message.
- linkstringA deep link (to a page in your app), or a link to a web page.
- titlestringThe title of your push notification.
- Contains properties that are not interpreted by the SDK but are defined by FCM. You need to write your own code to handle these Android push features.
- Properties supported specifically by Android on FCM.
- body_loc_argstringVariable string values used in place of the format specifiers in
body_loc_keyto localize the body text to the user's current localization. See Formatting and Styling for more information. - body_loc_keystringString resource key used to localize the body text. See Android String resources.
- click_actionstringThe action that occurs when a user taps on the notification. Launches an activity with a matching intent filter when a person taps the notification.
- colorstringThe notification's icon color in
#rrggbbformat. - iconstringSets the notification icon to
myiconfor drawable resourcemyicon. If you don't send this key, FCM displays the launcher icon from your app manifest. - soundstringThe sound that plays when the device receives the notification. Supports
"default"or the filename of a sound resource bundled in your app. Sound files must reside in/res/raw/. - tagstringAn identifier you use to replace an existing notification. If a notification with the same tag is already showing, the new one replaces it. Leave it empty to create a new notification each time.
- title_loc_argstringVariable string values used in place of the format specifiers in
title_loc_keyto localize the title text to the user's current localization. See Formatting and Styling for more information. - title_loc_keystringString resource key used to localize the title text. See Android String resources.
Next steps
After you set up push notifications, configure App Groups for reliable delivery tracking on iOS. Without App Groups, iOS can end the Notification Service Extension before delivery metrics are sent, which means some data may never reach Customer.io. App Groups provide shared storage so the SDK can recover any lost metrics on the next app launch.