React Native SDK Integration
Last updated
Last updated
Quick Steps Guidelines
Step 1: Install React Native
Follow the installation guide to set up React Native.
Step 2: Setup iOS
Get your Apple Push Notification and complete the setup steps.
Step 3: Setup Android
Create a project on Firebase Console and follow the Android setup instructions.
Please see the following document on React Native Installation.
Run the following command to link the SDK:
No extra Netmera SDK libraries are required for Android or iOS.
Add the following line to your Podfile
to integrate iOS SDK into your project.
Log in to developer.apple.com with your Apple Developer account.
Generate an Apple Push Notification Certificate for your app.
Export the certificate using Keychain Access on your Mac.
Upload the exported certificate to the Netmera panel by navigating to Developer > Push Backends > iOS in the left menu.
Bundle IDs should match on your project, certificate and panel:
Ensure that the certificate you upload to the panel matches the bundle ID of your project. Additionally, set your project's bundle ID in the panel to ensure consistency. The bundle ID of your project, the certificate, and the one specified in the panel must all align.
Certificate types:
For apps downloaded from the App Store or tested via TestFlight, the certificate type should be set to "prod".
For apps built directly from Xcode, the certificate type must be set to "dev".
If you have problems sending push notifications when you build from Xcode, verify the certificate type on the Developer > Push Backends > iOS page in Panel.
Install Pods
Navigate to the iOS folder in your terminal and run:
Initialize Netmera in AppDelegate
Update your AppDelegate
class with the following codes:
To obtain your SDK API Key:
Go to the Netmera Panel.
Navigate to Developer > API > SDK API Key.
Copy your SDK API Key from this section.
Use this key to replace the [<YOUR NETMERA API KEY>]
placeholder in the sample code.
React Native Push Handling
When triggering [RNNetmeraRCTEventEmitter onPushReceive]
in AppDelegate
, the corresponding method is called in React Native:
Request push notification authorization:
For versions 3.14.4 and above, refer to the Media Push.
Add the following outside of your target in your Podfile
:
Replace X.X.X
with the latest version from the SDK Versions page > React Native SDK Versions
In Netmera Panel:
Navigate to Developers > Netmera Onboarding.
Select Android and click Start to proceed.
Netmera uses Firebase Cloud Messaging (FCM) for delivering push notifications.
Go to the Firebase Developers Console and create a Firebase project.
Generate a new Private Key (JSON file) for your project.
Upload this file in Netmera Panel > Developers > Netmera Onboarding > Android > Step 2: Create A Firebase Configuration > FCM Service Account Key.
Choose the React Native SDK based on your application framework.
Important Notes:
Do not use the API key from a test panel in production.
Each panel has a unique API key, and using the wrong one can result in data misdirection or errors.
To obtain your SDK API Key:
Go to the Netmera Panel.
Navigate to Developer > API > SDK API Key.
Copy your SDK API Key from this section.
Netmera Android SDK is served via maven repository. All you need to do is adding following configurations to your build.gradle
file. AndroidManifest
and other resource configurations are done automatically via Android gradle build tool.
Projectโs build.gradle
File
Add the following to your project-level build.gradle
file:
Appโs build.gradle
File
Add the required dependency and plugins to your app-level build.gradle
file:
At the top of your appโs build.gradle
, include:
Important Note for Obfuscation:
If your code is obfuscated, there is no need to add any special rules for Netmera. Its functionality is unaffected by code obfuscation.
In your app, locate or create a class that extends android.app.Application
.
Inside this class, add the following code to the onCreate()
method:
No class that extends android.app.Application
If you donโt have this class, create one.
Then, add it to your AndroidManifest.xml
file under the <application>
tag using the android:name.
To obtain your SDK API Key:
Go to the Netmera Panel.
Navigate to Developer > API > SDK API Key.
Copy your SDK API Key from this section.
Use this key to (<YOUR NETMERA API KEY>)
placeholder in the sample code.
Custom Firebase Messaging Integration
If you are using Firebase Messaging in your app, you can use these code snippets to handle Netmera push notifications:
Get Firebase Token:
Handle Incoming Firebase Messages:
Custom Huawei Messaging Integration
For Huawei messaging, you can use the following code to manage push notifications:
Get Huawei Token:
Handle Incoming Huawei Messages:
Android 13 introduced significant changes to how push notification permissions are handled.
Increased User Control: Apps targeting API Level 33 and above now have more control over when and how they request push notification permissions. This allows for a more user-friendly and context-aware permission request experience.
Automatic Permission Requests for Older Apps: For apps targeting API Level 32 and below running on Android 13, the system automatically prompts the user for push notification permission when the app creates its first notification channel.
Impact on Netmera SDK Users:
The Netmera SDK initializes and creates notification channels during the app's startup. Consequently:
On Android 13: For apps targeting API Level 32 and below, this initialization process will trigger the automatic system prompt for push notification permission.
On Android 12 and below: The system generally assumes push notification permission has already been granted.
If you initialize the Netmera SDK at app startup (which is recommended), the system will automatically request push notification permissions on Android 13 devices for apps targeting API Level 32 and below. For devices running Android 12 or earlier, the system assumes permission is already granted.
For Android apps targeting API Level 33, the Netmera SDK provides two key methods to handle notification permissions:
Check Notification Permission Status:
This method checks if the app has the necessary permissions to send push notifications. It returns true
if the permission is granted, otherwise false
.
Request Notification Permissions:
Use this method to request notification permissions from the user. Call this method when you need to prompt the user for permissions at any time.
Push Enable/Disable User Flow:
Granting Permission:
The user triggers requestNotificationPermissions()
, and if they grant permission, a push enable request is sent.
Handling Denial:
If the user denies permission, avoid resending the request immediately (as recommended by Google). Instead, the SDK opens the app's notification settings. The user can grant permission from the settings and return to the app, where a push enable request is sent.
Denying Permission:
If the user triggers requestNotificationPermissions()
and denies permission, a push disable request is sent.
Reattempt After Denial:
If denied, avoid immediate re-request. The SDK will open the app's notification settings. If the user cancels (presses the back button), a push disable request is sent.
React Native SDK integration has been successfully completed, and your devices are now ready to receive the following types of push notifications sent via the Netmera Dashboard:
Standard Push Notifications
Interactive Push Notifications
Widgets
Push Notifications with Deeplinks