Setup
Installation
Add the following code to your
pubspec.yamlfiledependencies: cleverpush_flutter: ^1.24.36Run
flutter packages get
iOS Dependency Manager (CocoaPods, Swift Package Manager, or both)
The CleverPush Flutter SDK ships with both integration methods, so you can use whichever your project relies on:
- a CocoaPods spec (
cleverpush_flutter.podspec) - a Swift Package Manager (SPM) manifest (
Package.swift)
You only need one of them at build time. Picking a method up front avoids the most common iOS build errors (see Troubleshooting).
How Flutter decides: If Swift Package Manager is enabled in your Flutter installation (
flutter config --enable-swift-package-manager) and every iOS plugin supports SPM,flutter run/flutter buildwill automatically route plugins through SPM and add SPM integration to your Xcode project. If SPM is disabled, plugins are provided via CocoaPods. You can check your current setting withflutter config.
Option A — CocoaPods only (recommended if you are unsure)
Disable Swift Package Manager so plugins are always provided via CocoaPods:
flutter config --no-enable-swift-package-managerFrom your app directory, install everything cleanly:
flutter clean flutter pub get cd ios pod installpod installshould reportcleverpush_flutteramong the installed pods. Always open the.xcworkspace(not the.xcodeproj) in Xcode.
Option B — Swift Package Manager only
Enable Swift Package Manager:
flutter config --enable-swift-package-managerBuild through the Flutter tooling so the Swift packages are resolved and wired into Xcode:
flutter clean flutter pub get flutter run # or: flutter build iosImportant: With SPM enabled, the plugin is not added to your Podfile. A plain
pod installwill not compile the plugin. You must build at least once withflutter run/flutter build iosso SPM resolves the package — otherwise Xcode reportsModule 'cleverpush_flutter' not found.
Option C — Using both (CocoaPods for an extension + SPM for plugins)
A common real-world case: your app uses SPM for plugins, but the Notification Service Extension still needs the CleverPush/CleverPushExtension CocoaPod. This works, but keep these rules in mind:
- Build the app with
flutter run/flutter build ios(so SPM resolves the plugin), not by building the Runner target directly in Xcode right after a manualpod install. - Keep the CleverPush version used by the extension identical to the version the plugin depends on (see step 2 below), otherwise CocoaPods will install two different CleverPush versions.
Setup iOS
Enable the required capabilities
Go to your root project and switch to the tab "Capabilities"
Enable "Push Notifications"
Enable "Background Modes" and check "Remote notifications"
Add Notification Service Extension
This is required for correctly tracking notification deliveries and for displaying big images or videos in notifications.
Select
File>New>Targetin XcodeChoose
Notification Service Extensionand pressNextEnter
CleverPushNotificationServiceExtensionas Product Name, chooseObjective-Cas language and pressFinishPress
Activateon the next promptAdd the following at the bottom of your Podfile
target 'CleverPushNotificationServiceExtension' do use_frameworks! pod 'CleverPush/CleverPushExtension', '1.34.45' endPin the version. Set the
CleverPush/CleverPushExtensionversion to the same CleverPush version the SDK depends on (you can see it incleverpush_flutter.podspec→s.dependency 'CleverPush', '...'). If you leave it unpinned, CocoaPods may install a different (older) version for the extension than for the main app, sopod installends up installing two CleverPush versions. The app and the extension must use the same version. 6. Runpod install7. OpenNotificationService.mand replace the whole content with the following:#import <CleverPushExtension/CleverPushExtension.h> #import "NotificationService.h" @interface NotificationService () @property (nonatomic, strong) void (^contentHandler)(UNNotificationContent *contentToDeliver); @property (nonatomic, strong) UNNotificationRequest *receivedRequest; @property (nonatomic, strong) UNMutableNotificationContent *bestAttemptContent; @end @implementation NotificationService - (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler { self.receivedRequest = request; self.contentHandler = contentHandler; self.bestAttemptContent = [request.content mutableCopy]; [CleverPushExtension didReceiveNotificationExtensionRequest:self.receivedRequest withMutableNotificationContent:self.bestAttemptContent]; self.contentHandler(self.bestAttemptContent); } - (void)serviceExtensionTimeWillExpire { [CleverPushExtension serviceExtensionTimeWillExpireRequest:self.receivedRequest withMutableNotificationContent:self.bestAttemptContent]; self.contentHandler(self.bestAttemptContent); } @end
Create your iOS push certificate
- Open Keychain Access on your Mac. (Application > Utilities > Keychain Access).
- Select Keychain Access > Certificate Assistant > Request a Certificate From a Certificate Authority...
- Select the "Save to disk" option and enter any information in the required fields
- Go to the Apple developer portal, select your app and press "Edit"
- Enable "Push notifications" and press "Done"
- Go to the Create new certificate page, select "Apple Push Notification service SSL" and press "Continue"
- Select your Application Bundle ID and press "Continue"
- Press "Choose File...", select the previously generated "certSigningRequest" file and then press "Generate"
- Press "Download" and save your certificate
- Click on the downloaded .cer file, Keychain Access should open
- Select Login > My Certificates then right click on your key and click "Export (Apple Production iOS Push Services: com.your.bundle)..."
- Give the file a unique name and press save, be sure to leave the password field blank!
- Upload your certificate in the CleverPush channel settings
Add AppGroup (optional but recommended)
This is required for getting the received notifications via the
getNotificationsmethod and also for automatic Badge Counting (i.e. when usingsetIncrementBadge(true)).- Select your main application Target in Xcode
- Go to
Capabilitiesand activateApp Groups - Create a new App Group with the following Scheme:
group.YOUR.BUNDLE.ID.cleverpush(replaceYOUR.BUNDLE.IDwith your application's bundle identifier). - Enable the created App Group by checking the checkbox next to it
- Select the
CleverPushNotificationServiceExtensiontarget and also enable the created App Group underCapabilities
Setup Android
- Setup Firebase inside your Android Runner App and register the Sender ID and the API Key inside the CleverPush Channel settings. Please refer to the official docs: https://firebase.google.com/docs/android/setup