iOS Push Integration
This document guides you to integrate apns push notification in react native iOS application.
Major Release (V 1.0.0) 🚧
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:
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
AppDelegate.h file changes in iOS folder
Add the below code in AppDelegate.h file inside iOS folder
Register for push notification in AppDelegate.m file
Call registerForPushNotifications method below the SuprSend sdk initialised 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 the users to allow push notifications on their device:
Enable sending and tracking of push notifications
To enable sending iOS APNS token to SuprSend backend, delivery and tracking of push notification delivery/clicks/dismiss events, add below code snippet at the end of AppDelegate.m file before @end at last line
iOS Push notifications only work on real devices so while developing/testing use real device to test it instead of simulators
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 at the end of existing code like shown in image. Replace <your notification service name> with name you given to notification service while creating it. After that Run pod install
.
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.
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