iOS Push Integration
This document guides you to integrate apns push notifications in native iOS application.
Add capabilities in iOS application
-
Inside Targets select
signing and capabilities
-
Click on
+capabilities
and selectPush Notifications
andBackground 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.
-
Then in Next popup give it any product name, select your team, select swift language and click finish.
After clicking on “Finish”, a folder will be created with your given product name. Inside that there will be NotificationService.swift file like below.
In your project podFile add following snippet to add support for notification service to access SuprSend SDK methods. In below snippet replace with name you given to notification service while creating it.
Replace the content in NotificationService.swift file with below code to start sending push notifications with 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.