Setup
Installation
Add the following code to your
pubspec.yaml
filedependencies: cleverpush_flutter: ^1.23.32
Run
flutter packages get
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
>Target
in XcodeChoose
Notification Service Extension
and pressNext
Enter
CleverPushNotificationServiceExtension
as Product Name, chooseObjective-C
as language and pressFinish
Press
Activate
on the next promptAdd the following at the bottom of your Podfile
target 'CleverPushNotificationServiceExtension' do use_frameworks! pod 'CleverPush' end
Run
pod install
Open
NotificationService.m
and replace the whole content with the following:#import <CleverPush/CleverPush.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]; [CleverPush didReceiveNotificationExtensionRequest:self.receivedRequest withMutableNotificationContent:self.bestAttemptContent]; self.contentHandler(self.bestAttemptContent); } - (void)serviceExtensionTimeWillExpire { [CleverPush 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
getNotifications
method and also for automatic Badge Counting (i.e. when usingsetIncrementBadge(true)
).- Select your main application Target in Xcode
- Go to
Capabilities
and activateApp Groups
- Create a new App Group with the following Scheme:
group.YOUR.BUNDLE.ID.cleverpush
(replaceYOUR.BUNDLE.ID
with your application's bundle identifier). - Enable the created App Group by checking the checkbox next to it
- Select the
CleverPushNotificationServiceExtension
target 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