React Native SDK
Detailed technical documentation on the Lemnisk React Native SDK to send data from your React Native apps to your destinations via Lemnisk.
Last updated
Detailed technical documentation on the Lemnisk React Native SDK to send data from your React Native apps to your destinations via Lemnisk.
Last updated
Lemnisk React Native SDK can be used to track and send user events from your React Native application to various destinations of your choice. These destinations can be configured in the CDP Dashboard.
The recommended way to install the React Native SDK is through . You may also use to install the SDK.
Add the Lemnisk React Native dependency to your project by using the following command:
Run the following command to update the Pods in your Project'sios
directory:
Manifest File Changes
In the Package Explorer, open the AndroidManifest.xml
of your Android project and make the following changes
Add the below meta tags, replacing the placeholders with associated values given below:
The CampaignId
and serverUrl
will be provided by the Lemnisk Account Manager.
Add Firebase SDK
Lemnisk account manager will provide google-services.json. This google-services.json needs to be placed at root level in the app module.
Gradle changes
Manifest Changes
In the Package Explorer open the AndroidManifest.xml of your Android project and make the following changes:
Add the following meta-tags
NOTIFICATION_ICON
is displayed at the left of a notification
NOTIFICATION_ICON_SMALL
is displayed in the notification bar. This should be white icon on a transparent background
Add the following services for receiving the FCM token and messages.
Mandatory intent service for doing the heavy lifting
To support app-based deep link from Android 11 and onwards, following permission needs to be added to AndroidManifest.xml
of the app.
If you are targeting Api level >= 33 then you must ask user permission for push notifications at runtime. For that you can call the below function at appropriate place in your app.
We recommend calling this method on every app launch.
FCM deprecated legacy APIs for HTTP and requires OAuth 2.0 authorization for sending push notifications. In order to generate Auth2.0 access token we need following credentials from the clients FCM project.
This can be retrieved from Project settings -> General -> Project ID
To authenticate a service account and authorize it to access Firebase services, you must generate a private key file in JSON format.
To generate a private key file for your service account:
Click Generate New Private Key, then confirm by clicking Generate Key.
Securely store the JSON file containing the key.
Please share the above two credentials with lemnisk.
Integration through CocoaPods
CocoaPods is a dependency manager for Objective C & Swift projects and makes integration easier.
If you don't have CocoaPods installed, you can do it by executing the following line in your terminal:
If you don't have a Podfile, create a plain text file named Podfile
in the Xcode project directory with the following content, making sure to set the platform and version that matches your main app, Notification Content Extension and Notification Service Extension. Add the below code in the Podfile
Import the Lemnisk SDK by using the following import statement in your AppDelegate or at the entry point of your App if it is iOS 15+
If the entry point is a .m file, use the following import statement.
If the entry point is a .mm file use the following instead
In the bridging header for the entry point file you need to add below import statements.
In your AppDelegate or in the entry point file, please add the following code snippet in didFinishLaunchingWithOptions to initialise the Lemnisk SDK.
You need to call below method before appLaunch sequence completes for example you can call it in didFinishLaunchingWithOptions method.
Enable remote notifications and Background fetch in Background modes capability of your main target as show below.
Our background task identifier ("co.lemnisk.app.ios.refresh
") needs to be added in info.plist as shown in below screenshot.
This task helps in ensuring high push notifications deliverability.
make sure to call registerForPushNotifications
method only after this method is called.
Important note: If you already have some BGApprefresh task that you registered for your app instead of registering this task please get in touch with our Customer success team.
If you want to show the Push Notifications permission authorization prompt from AppDelege itself, then you can use the following SDK API to show the same to the user. If you wish to show the otherization from your ReactJs using JavaScript then you can skip then and use the respective SDK method described in the later sections.
We recommend calling this SDK method on every App launch
if registerLemniskNotificationTasks
is called then call registerForPushNotifications
only after registerLemniskNotificationTasks
is called.
Please ignore any of the compilation errors at this point in time till the pod install
command is run, which we will do in later steps
In your AppDelegate you need to enable swizzling for all and then only call our configure method.
And try to initialise our sdk after initialising any other sdk as we will be calling all the original methods that are swizzled so that it won't effect functionalities of other sdk's
From iOS 10+, we can show rich media Push Notifications with images, video, audio and a carousel. So please configure the below 2 extensions in your project if you don't have them already and configure Lemnisk SDK in them.
Notification Service Extension
We use Notification Service Extension to track the delivery of Push Notifications as well as downloading the Rich Media Push Notification attachments (image/video/audio etc)
Add a Notification Service Extension target to your project (File -> New -> Target -> Notification Service Extension)
Define the name for the Notification Service Extension in the next step
Now modify the NotificationService.swift
to look like the following code.
If you have multiple push providers you can implement NotificationService as mentioned below.
Notification Content Extension
This extension can be used if you want to show a carousel slider in a Push Notification.
Add a Notification Content Extension target to your project (File -> New -> Target -> Notification Content Extension)
Define the name for the Notification Content Extension in the next step.
Make sure the deployment target for notification content is set to iOS 10
Now modify the NotificationViewController.swift
to look like the following code.
Now install all the Lemnisk dependencies with the following command
This would install the Lemnisk framework along with the required dependencies for your app extension targets.
Changes in Frameworks, Libraries, and Embedded content for Notification Service Extension( only if sdk version <= 3.8.5)
For some reason, there is an issue with Pods being installed and Xcode reading it from the embedded pod's. And so we need to embed the LemniskRichNotification manually in the extension target's Frameworks, Libraries, and Embedded content and select Do Not Embed. You can refer to the same below.
Now select Do Not Embed
Changes in Frameworks, Libraries, and Embedded content for Notification Content Extension( only if sdk version <= 3.8.5)
For some reason, there is an issue with Pods being installed and Xcode reading it from the embedded pod's. And so we need to embed the LemnsikNotificationContent manually in the extension targets Frameworks, Libraries, and Embedded content and select Do Not Embed. You can refer to the same below.
Now select Do Not Embed
Changes in Frameworks, Libraries, and Embedded content for the App Target( only if sdk version <= 3.8.5)
For some reason, there is an issue with Pods being installed and Xcode reading it from the embedded pod's. So you may end up seeing this error when you are trying to validate your build.
To resolve this, we need to embed the LemniskRichNotification and LemnsikNotificationContent manually in the Application target's Frameworks, Libraries, and Embedded content and select Embed & Sign. You can refer to the same below.
Configuring App Groups
Please follow the following procedure if you are using the Xcode Auto Sign, otherwise please scroll below to add the App Groups manually via the Apple Developer Console.
With Xcode Auto Sign
Go to App Groups
capability from the Xcode’s Singing & Capabilities
for all the targets (App, NotificationServiceExtension and NotificationContentExtension) as shown in the following screenshot.
Now search for App group
and select App Groups
Now create the required App Groups
Id by inputting a value similar to your Bundle Id (need not be same as BundleId) which will have group.
as the prefix
Now finally select group id
that we have just created
Similarly, select the already created same AppGroup for the other two targets - Notification Service Extension and Notification Content Extension.
Now close and reopen your project's xc-workspace file and at this point in time, all the build errors should be resolved.
From Apple Developer Console
Goto Identifiers
tab in the Apple Developer Console and click on App Groups
as shown in the below screenshot.
Now tap +
to create a new App Group
Select App Groups
on the next screen as shown below
Now fill the Description
and the Identifier
(App Group name) and click Continue
On the next screen, click Register
Now go to Identifiers
tab, click on your App Bundle identifier
Now check on App Groups
and click configure
On the next step, select the group we have created in the previous step and click continue
and then Save
Now go to Profile
tab and select your profile, if it shows invalid
then click Edit
and Save
. Then download the file and use it in the Xcode.
Finally in the Xcode, go to Singing & Capabilities
as shown in the following screenshot
Now search for App group
and select App Groups
Now select the App group
that we have created earlier in the Apple Developer Console
Now repeat steps 6-12 for App extension targets as well (Now go to Identifiers
step above)
Please add the Privacy - Tracking Usage Description
key in your main app Info.plist
as this will be used as a description while showing the Tracking description if you would want to enable the IDFA
tracking.
To enable/disable the IDFA
tracking you can do so by adding the properties LemniskUseIDFA
and LemniskShowIDFAPrompt
as Boolean
to your main app's Info.plist
file.
Please find the description of the above LemniskUseIDFA
and LemniskShowIDFAPrompt
below
LemniskUseIDFA
- Will grant IDFA usage to Lemnisk
LemniskShowIDFAPrompt
- To ask the user for Tracking permission or not
Please update the Notification Content Extension Info.plist
's UNNotificationExtensionCategory
to Array
and add the required categories from the following entries.
i. carousel
Add the following properties under NSExtensionAttributes
i. Add property UNNotificationExtensionDefaultContentHidden
as String and set its value to YES
ii. Add property UNNotificationExtensionUserInteractionEnabled
as Boolean and set its value to true
Once the SDK is added, you need to initialize the React Native SDK.
Import the SDK wherever you'd like to use it in your react codebase
If you want to show the Push Notification Authorization Prompt from your React Native code on any screen from your JS code, then you can call the following SDK API. Given you haven't already called this from your AppDelegate.
We recommend calling this method on every app launch.
The screen
call lets you record whenever a user sees a screen, in your mobile app, along with any properties about the screen.
Usage:
Example:
The identify
call lets you tie a user to their actions and record traits about them. It includes a unique User ID and any optional traits you know about the user, like their email, mobile, any other id etc.
Usage:
Example:
The track
call lets you record any actions your users perform, along with any properties that describe the action.
Usage:
Example:
Parameter
Type
Description
eventName
String
The name of the event you’re tracking
Lemnisk would need the cert.pem and key.pem files generated for your application to be able to send the App Push Notifications.
Following is the procedure to generate the cert.pem and key.pem files.
Open Keychain Access on your Mac (it is in Applications/Utilities) and choose the menu option Request a Certificate from a Certificate Authority
You should now see the following window:
Enter your email address here.
Enter your application name here, for example, I have entered "LemniskDemo". You can type anything you want here, but choose something descriptive. This allows us to easily find the private key later.
Check Saved to disk and click Continue.
If you go to the Keys section of Keychain Access, you will see that a new private key has appeared in your keychain.
Right-click on the new private key and choose Export.
Save the private key as LemniskDemoKey.p12 and enter a passphrase. (Do choose a passphrase that you can recall! Or you won’t be able to use the private key later.)
So log in to the Apple developer console & follow the below steps:
Assuming you have already created the Identifier for your app bundle id, now navigate to the Certificates section in the developer console. Click on the +
next to Certificates
Choose the Apple Push Notification service SSL (Sandbox & Production)
option and click on Continue
Now select the App Id
from the already registered (of your app) list in the Identifier
section and then click on Continue
Now click on Choose File
and select the CSR file that we have generated above and click on Continue
Now we have successfully generated the aps.cer
file, click on Download
to download the cer file. Let’s say the downloaded file name is aps.cer
So now we have three files:
The CSR
The private key as a p12 file (LemniskDemoKey.p12)
The SSL certificate (aps.cer)
You have to convert the certificate and private key into a format that is more usable. Because our server will need the cert.pem and key.pem file to deliver the push notification, now we will generate them by using the following procedure.
We are going to use the command-line OpenSSL tools for this. Open a Terminal and execute the following steps.
Convert the .cer file into a .pem file:
$ openssl x509 -in aps.cer -inform der -out LemniskDemoCert.pem
Convert the private key’s .p12 file into a .pem file:
$ openssl pkcs12 -nocerts -out LemniskDemoKey.pem -in LemniskDemoKey.p12
You first need to enter the passphrase for the .p12 file so that openssl can read it. Then you need to enter a new passphrase that will be used to encrypt the PEM file.
Note:
if you don’t enter a PEM passphrase, openssl will not give an error message but the generated .pem file will not have the private key in it.
Now let’s try to test whether the certificate works, by using our SSL certificate and private key:
$ openssl s_client -connect gateway.push.apple.com:2196 -cert LemniskDemoCert.pem -key LemniskDemoKey.pem
Now please share the following with your account manager for us to be able to send push notifications
cert.pem and key.pem (Generated above)
passphrase (if any given in the above steps)
bundle identifier of the app
Q1. What is the minimum Android and iOS versions supported by the Lemnisk React Native SDK?
Ans: iOS 13 and Android 5.0 or higher is supported.
Q2. I get the error LemniskSdk is not defined
. What do I do?
This error appears when you try to use the LemniskSdk
method before initialising the SDK in the application. Make sure to import the SDK at the top of your file before using it.
Q3. Is it required to link the SDK using react native link
?
If you running an older version of React Native, v.60 or lower, yes, it is mandatory to link the SDK with the react native link
command.
Q4. How to verify if the Lemnisk React Native SDK is installed correctly?
Import the SDK and run the application on your mobile device. If it runs without any errors, it is safe to assume that the SDK is installed and loaded correctly.
Q6. I am facing some performance issues with the SDK. What could be the issue?
In case you encounter any issues with the SDK, follow the steps below to fix the errors and run the SDK correctly.
Make sure that the SDK is installed and loaded properly. If npm install
or yarn add
is giving any problem while installation, please upgrade npm
or yarn
to the latest version.
Please check whether you are running on VPN or proxy that prevents SDK from functioning properly.
Make sure your system date and time is correct.
If nothing works, please contact us below.
Lemnisk clients that are running Android app push notifications are requested to provide the required FCM project credentials, to assist in by end of May 2024.
This is explained
Lemnisk sends push notifications to Android devices using .
Refer to Android and for more details.
In the Firebase console, open Settings > .
Please enable Push Notifications and AppGroup capability from our Xcode Signing & Capabilities Tab and use the Same AppGroup for all the 3 targets (App, Notification Service Extension and Notification Content Extension). You can find the documentation on how to enable AppGroup if you aren't familiar with this.
Now please enable the AppGroup capability from our Xcode Signing & Capabilities Tab and use the same AppGroup for all the 3 targets (App, Notification Service Extension and Notification Content Extension). You can find the documentation on how to enable AppGroup if you aren't familiar with this.
Now please enable the AppGroup capability from our Xcode Signing & Capabilities Tab and use the same AppGroup for all the 3 targets (App, Notification Service Extension and Notification Content Extension). You can find the documentation on how to enable AppGroup if you aren't familiar with this.
Q5. I built an app using . Can I install the Lemnisk React Native SDK with it?
No, because as of now, Expo doesn't support adding native modules in their application. However, you can your expo app and use our native and libraries.
React Native runs slow in DEBUG
mode. Try running the code in Production. Follow this to learn more. If it is still slow in Production mode, make sure the Lemnisk.DEBUG_MODE
is also set to false
in AndroidManifest.xml
file.
To know more about the Lemnisk React Native SDK you can .