Integrate React Native SDK - iOS

This document will cover SDK installation and initialization steps for your iOS application

Please follow the below steps for Suprsend SDK set up in your iOS project

Installation

Step 1. Install the Package using npm / yarn
Please skip this step if you have already installed this package for android setup

npm install @suprsend/react-native-sdk

// for updating sdk to latest version
npm install @suprsend/react-native-sdk@latest
yarn add @suprsend/react-native-sdk

// for updating sdk to latest version
yarn add @suprsend/react-native-sdk@latest

Step 1.1 Updating existing version

If you are upgrading the SDK version to the newer one, run pod update inside ios folder. This will update suprsend's native iOS SDK.

🚧

Updating existing iOS version to v1.0.0 or above

Starting from iOS version (v1.0.0 and above), 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 that to use the latest push integration steps


Step 2. Adding swift support and Bridge header
Our iOS SDK is written in swift language so it's necessary to add swift support in React native project as react native uses Objective-C for iOS. This is just a few steps process. You can skip this step if you already have swift language support in your project.

Follow below steps to add swift language support in your react native project:

  1. Open xcodeworkspace file inside iOS folder.
  2. Add file swift file to project like shown below.
2880
  1. Then select swift file and click on "Next" button
  2. Now give a suitable name to your file and click "Create"
  3. After that xcode popup will be shown asking to configure objective-c bridge header. Click on create bridge header button.

Thats it! your React native iOS project can now understand code written in swift language.


Step 3. Changes in PodFile and Run pod Install
SuprSend sdk needs iOS platform version of 13 or above, so check it inside PodFile and change if its less than 13.0 and then run pod install from inside iOS folder.

platform :ios, '13.0' // this version has to be 13 or greater

Step 4. Change iOS Deployment Target
SuprSend sdk needs an iOS deployment target of 11 or above, open your project in Xcode(project > ios > project.xcworkspace) and update the target as given in below image.


2. Initialization

Step 1. To integrate SuprSend in your iOS app, you'll need to imprt Suprsend iOS sdk in your application. In AppDelegate.m add the below mentioned code inside didFinishLaunchingWithOptions method, just before returning YES like in code below.

#import <UserNotifications/UserNotifications.h> //add this, needed as sdk internally depends on this package
#import <SuprSendSdk/SuprSendSdk-Swift.h> //add this

...

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  ...
  SuprSendSDKConfiguration* configuration = [[SuprSendSDKConfiguration alloc] initWithKey:@workspace_key secret:@workspace_secret baseUrl:nil]; // add this line
  [SuprSend.shared configureWithConfiguration:configuration launchOptions:launchOptions]; // add this line
  return YES;

Replace WORKSPACE KEY and WORKSPACE SECRET with your workspace values. You will get both the tokens from Suprsend dashboard (Settings page -> "API keys" section). For more details, check the documentation on 'Workspaces'.


Logging

By default the logs of SuprSend SDK are disabled. You can enable the logs just in debug mode while in development by the below condition.

suprsend.enableLogging(); // available from v2.0.2

// deprecated from v2.0.2
suprsend.setLogLevel(level)
suprsend.setLogLevel("VERBOSE")
suprsend.setLogLevel("DEBUG")
suprsend.setLogLevel("INFO")
suprsend.setLogLevel("ERROR")
suprsend.setLogLevel("OFF")