SDK Integration

Step 1: Install React Native

  1. Install Netmera

yarn add react-native-netmera
  1. Link Netmera (for React Native versions < 0.60)

Skip this step if you are using React Native version 0.60 or greater.

react-native link react-native-netmera

For both native sides (Android & iOS), you don't have to include extra Netmera SDK libraries.

Step 2: Setup iOS

1. Create an Apple Push Notification Certificate

  1. Log in to developer.apple.com with your Apple Developer account.

  2. Generate an Apple Push Notification Certificate for your app.

  3. Export the certificate using Keychain Access on your Mac.

  4. 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.

Creating an APNS .p12 Certificate

2. Integrate & Initialize Netmera iOS SDK

Install Pods

Navigate to the iOS folder in your terminal and run:

$ pod install

Initialize Netmera in AppDelegate

Netmera iOS SDK must be initialized in the AppDelegate file. Follow the steps based on your project type:

  • For Swift Projects: Modify your AppDelegate.swift file.

  • For Objective-C Projects: Modify your AppDelegate.m and AppDelegate.h files.

Modify your AppDelegate.swift file:

import RNNetmera
import Netmera

@main
class AppDelegate: RCTAppDelegate, UNUserNotificationCenterDelegate, NetmeraPushDelegate {
    override func application(
        _ application: UIApplication,
        didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil
    ) -> Bool {
        
        if #available(iOS 10.0, *) {
            UNUserNotificationCenter.current().delegate = self
        }

        // Enable logging (Optional: Set to false in production)
        RNNetmera.logging(true)

        // Initialize Netmera with your API Key
        RNNetmera.initNetmera("<YOUR NETMERA API KEY>") // Replace with your API key
        RNNetmera.setPushDelegate(self)

        // Set App Group Name (Required for rich notifications)
        Netmera.setAppGroupName("<YOUR APP GROUP NAME>") // Replace with your App Group Name

        return super.application(application, didFinishLaunchingWithOptions: launchOptions)
    }

    // MARK: - Push Notification Handling

    @available(iOS 10.0, *)
    func userNotificationCenter(
        _ center: UNUserNotificationCenter,
        didReceive response: UNNotificationResponse,
        withCompletionHandler completionHandler: @escaping () -> Void
    ) {
        let userInfo = response.notification.request.content.userInfo
        if response.actionIdentifier == UNNotificationDismissActionIdentifier {
            RNNetmeraRCTEventEmitter.onPushDismiss(["userInfo": userInfo])
        } else if response.actionIdentifier == UNNotificationDefaultActionIdentifier {
            RNNetmeraRCTEventEmitter.onPushOpen(["userInfo": userInfo])
        }
        completionHandler()
    }

    @available(iOS 10.0, *)
    func userNotificationCenter(
        _ center: UNUserNotificationCenter,
        willPresent notification: UNNotification,
        withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void
    ) {
        completionHandler([.alert])
        RNNetmeraRCTEventEmitter.onPushReceive(["userInfo": notification.request.content.userInfo])
    }

    override func application(
        _ application: UIApplication,
        didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data
    ) {
        RNNetmeraRCTEventEmitter.onPushRegister(["pushToken": deviceToken])
    }
}

React Native Push Handling

When triggering [RNNetmeraRCTEventEmitter onPushReceive] in AppDelegate, the corresponding method is called in React Native:

export const onPushReceive = async (message) => {
    console.log("onPushReceive: ", message);
};

3. iOS10 Media Push Configuration

  1. For versions 3.14.4 and above, complete the steps found in Media Push.

  2. Update your Podfile by adding the following lines outside of your target:

pod "Netmera", "X.X.X-WithoutDependency"
pod "Netmera/NotificationServiceExtension", "X.X.X-WithoutDependency"
pod "Netmera/NotificationContentExtension", "X.X.X-WithoutDependency"

Replace X.X.X with the latest version from the SDK Versions page > Changelog

Sample Project

Step 3: Setup Android

1. Netmera Android Onboarding

In Netmera Panel:

  • Navigate to Developers > Netmera Onboarding.

  • Select Android and click Start to proceed.

2. Create a Firebase Configuration

Netmera uses Firebase Cloud Messaging (FCM) for delivering push notifications.

  1. Go to the Firebase Developers Console and create a Firebase project.

  2. Generate a new Private Key (JSON file) for your project.

  3. Upload this file in Netmera Panel > Developers > Netmera Onboarding > Android > Step 2: Create A Firebase Configuration > FCM Service Account Key.

3. Select a Target SDK

Choose the React Native SDK based on your application framework.

4. Integrate and Initialize React Native SDK

5. Integrate Netmera Android SDK

Netmera Android SDK is available through the Maven repository. Add the following configurations to your build.gradle file. The AndroidManifest and other resource settings are automatically managed by the Android Gradle build tool.

Gradle Configuration

  1. Project’s build.gradle File

Add the following to your project-level build.gradle file:

buildscript {
    repositories {
        google()
        jcenter()
        maven { url 'https://developer.huawei.com/repo/' }
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:X.X.X'
        classpath 'com.google.gms:google-services:X.X.X'
        classpath 'com.huawei.agconnect:agcp:X.X.X.X'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        maven { url 'https://maven.google.com' }
        maven { url 'https://developer.huawei.com/repo/' }
        maven { url "https://release.netmera.com/release/android" }
    }
}
  1. App’s build.gradle File

Add the required dependency and plugins to your app-level build.gradle file:

dependencies {
    implementation 'androidx.core:core:1.X.X'
}
  1. At the top of your app’s build.gradle, include:

apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.huawei.agconnect'

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.

6. Initialize Netmera Android SDK

  1. In your app, locate or create a class that extends android.app.Application and implements com.facebook.react.ReactApplication

  1. Inside this class, add the following code to the onCreate() method

import com.netmera.reactnativesdk.RNNetmera;
import com.netmera.reactnativesdk.RNNetmeraConfiguration;

public class MainApplication extends Application implements ReactApplication {
    @Override
    public void onCreate() {
        ...
        RNNetmeraConfiguration netmeraConfiguration = new RNNetmeraConfiguration.Builder()
            .firebaseSenderId(<YOUR GCM SENDER ID>)
            .huaweiSenderId(<YOUR HMS SENDER ID>)
            .apiKey(<YOUR NETMERA API KEY>)
            .logging(true) // Enables Netmera logs.
            .build(this);

        RNNetmera.initNetmera(netmeraConfiguration);
    }
}

Step 4: Setup React Native

Complete Push Callback Methods

Implement the necessary push notification callback methods in your React Native project in the following page:

Push Callbacks

Step 5: Netmera SDK Push Notification Permission Methods

On iOS and Android 13+ devices, a runtime push notification permission request is required. You can use the following methods to check users' push notification status and request notification permission.

  1. Request Push Notification Authorization

Netmera.requestPushNotificationAuthorization();

Push Enable/Disable User Flow:

  1. Granting Permission:

    • The user triggers requestPushNotificationAuthorization(), and if they grant permission, a push enable request is sent.

  2. 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.

  3. Denying Permission:

    • If the user triggers requestPushNotificationAuthorization() and denies permission, a push disable request is sent.

  4. 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.

  1. Check Notification Permission Status

This method allows checking whether the necessary permissions for the application have been obtained.

Netmera.checkNotificationPermission().then(status => {
   //NotificationPermissionStatus.NotDetermined
   //NotificationPermissionStatus.Blocked
   //NotificationPermissionStatus.Denied
   //NotificationPermissionStatus.Granted
 });

Responses

When this method is called, it would return one of the following responses:

  1. NOTDETERMINED The user has opened the app but hasn't made a decision about notification permissions yet.

  2. GRANTED The user has granted notification permission, and the app can send notifications.

  3. DENIED The user has denied permission or has blocked notifications through system settings.

React Native SDK Integration Complete

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

Last updated

Was this helpful?