iOS Push Integration
This document guides you to integrate apns push notification in flutter iOS application.
Starting from iOS version v1.0.0, we have introduced explicit push notification permission and option to add images in your notification. Also, introduced background mode for improved tracking of notification delivery.
If you are using an iOS version older than v1.0.0 and upgrading to the new version. Please ensure to use the latest integration steps, especially for below methods:
Example flutter repository with this implementation can be found here
Add capabilities in iOS application
-
Inside Targets select signing and capabilities
-
Click on +capabilities and select Push Notifications and Background Modes
In Background Modes, select Remote Notifications option. We use background notifications to receive delivery reports when your app is in quit and background state. Refer doc to know more about background notification
Register for push notification in AppDelegate.swift file
Call registerForPushNotifications
method below the SuprSend SDK initialized code which will register the iOS device for push service
Asking User to send push notifications
There are 2 ways in which your app can prompt users to allow push notifications on their devices:
Enable sending and tracking of push notifications
Receiving iOS APNS token sending to backend and listening for push notification and tracking user notification clicks can be done using the following snippet of code. Directly copy and paste it at end of the AppDelegate.swift file inside AppDelegate class.
iOS Push notifications only work on real devices so while developing/testing use real device to test it instead of simulators. From Xcode-15 push support can be tested in simulators as well.
Adding support for Notification service.
For better notification status (delivered, seen) tracking this step is needed.
In Xcode go to File > New > Target.
Select Notification Service Extension from the template list.
Name your Notification Service
Then in Next popup give it name to your notification service, select your team, select swift language and click finish.
A folder will be created
After clicking on Finish
, a folder will be created with your given product name. Inside that there will be NotificationService.swift
file like below.
Rename and Run the pod install
In your project podFile
add following snippet. Replace <your notification service name>
with name you given to notification service while creating it. After that Run pod install
.
Replace values with your Workspace Key and Workspace Secret.
Replace the content in NotificationService.swift
file with below code. In this snippet on line 11, 12 replace values with your workspace key and workspace secret.
Final Step
Runner Target inside Build Phases, drag Embedded Foundation Extensions
section and drop it below theCopy Bundle Resources
section like in image.
You are now all set to send push notifications. All you have to do is add iOS vendor configuration on SuprSend dashboard and your push notifications will be configured. Please refer vendor integration guide to integrate your apns push service.