Skip to content

A wrapper around the iOS and Android AEP mobile SDK to allow for integration with React Native applications.

License

Notifications You must be signed in to change notification settings

adobe/aepsdk-react-native

aepsdk-react-native

license CircleCI

About this project

This repository is a monorepo and contains a collection of React Native modules for Adobe Experience Platform Mobile SDK as listed below. These modules can be found in the packages directory.

Package Name Latest Version Native Extension
@adobe/react-native-aepcore (required) npm version npm downloads Mobile Core
@adobe/react-native-aepuserprofile npm version npm downloads Profile
@adobe/react-native-aepedge npm version npm downloads Edge
@adobe/react-native-aepedgeidentity npm version npm downloads EdgeIdentity
@adobe/react-native-aepedgeconsent npm version npm downloads EdgeConsent
@adobe/react-native-aepedgebridge npm version npm downloads EdgeBridge
@adobe/react-native-aepmessaging npm version npm downloads Messaging
@adobe/react-native-aepassurance npm version npm downloads Assurance
@adobe/react-native-aepoptimize npm version npm downloads Optimize
@adobe/react-native-aepplaces npm version npm downloads Places
@adobe/react-native-aeptarget npm version npm downloads Target
@adobe/react-native-aepcampaignclassic npm version npm downloads CampaignClassic

Note

Since version 5.0.0 of the Adobe React Native SDK, all React Native libraries that share the same major version are compatible with each other.

Note

The React Native libraries within this repository are specifically designed to support the Android and iOS platforms only.

Requirements

  • React Native

Requires React Native (0.60.0 and above)

  • Xcode

To submit iOS apps to the App Store, you must build them using Xcode 15 or later, as required by Apple.

iOS Privacy Manifest

Important

Adobe Experience Platform React Native 6.x libraries now depend on Experience Platform iOS 5.x SDKs, which have been updated to align with Apple's latest guidelines on privacy manifest. For further details on how Apple's privacy-related announcements affect the Adobe mobile SDK for iOS, please refer to this document.

React Native New Architecture Support

React Native 0.7x introduced support for a new architecture. We don't yet support the new architecture.

Expo Support

Please refer to the Expo Integration document for guidance on integrating the SDK with Expo projects.

Installation

You need to install Adobe Experience Platform Mobile SDK with npm packages and configure the native Android/iOS project in your React Native project.

Note: If you are new to React Native, we suggest you follow the React Native Getting Started page before continuing.

Install AEP npm packages

Adobe Experience Platform Mobile SDK packages can be installed from npm command.

Note: @adobe/react-native-aepcore is required to be installed.

Install the @adobe/react-native-aep{extension} package:

cd MyReactApp
npm install @adobe/react-native-aep{extension}

Alternatively, include the Adobe Experience Platform npm packages as dependencies in the app’s package.json.

The following code snippet shows for Mobile Core and Edge Network extensions as an example in package.json:

...
"dependencies": {
    "react-native": "0.72.5",
    "@adobe/react-native-aepcore": "^6.0.0", //core is required and includes aepcore, aepsignal, aeplifecycle, aepidentity libraries
    "@adobe/react-native-aepedge": "^6.0.0",
    "@adobe/react-native-aepedgeidentity": "^6.0.0",
    "@adobe/react-native-aepedgeconsent": "^6.0.0",
...
},

Inside of the app directory, run

#if using node package manager
npm install

or

#if using yarn package manager
yarn install
ios development

For iOS development, after installing the plugins from npm, download the pod dependencies by running the following command:

cd ios && pod install && cd ..

To update native dependencies to latest available versions, run the following command:

cd ios && pod update && cd ..

Initializing

Initializing the SDK should be done in native code inside your AppDelegate (iOS) and MainApplication (Android). The following code snippets demonstrate how to install and register the AEP Mobile Core and Edge Network extensions. Documentation on how to initialize each extension can be found in ./packages/{extension}/README.md.

iOS
//AppDelegate.h
@import AEPCore;
@import AEPServices;
@import AEPLifecycle;
@import AEPSignal;
@import AEPEdge;
@import AEPEdgeIdentity;
@import AEPEdgeConsent;
...
//AppDelegate.m
...
@implementation AppDelegate
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  [AEPMobileCore setLogLevel: AEPLogLevelDebug];
  [AEPMobileCore configureWithAppId:@"yourAppID"];

  const UIApplicationState appState = application.applicationState;

  [AEPMobileCore registerExtensions: @[
      AEPMobileLifecycle.class,
      AEPMobileSignal.class,
      AEPMobileEdge.class,
      AEPMobileEdgeIdentity.class,
      AEPMobileEdgeConsent.class,
  ] completion:^{
    if (appState != UIApplicationStateBackground) {
       [AEPMobileCore lifecycleStart:nil}];
    }
  }];
  return YES;
}

@end

To enable the Lifecycle metrics, implement the Lifecycle APIs

Hint : While running iOS application after Adobe Experience Platform SDK installation. If you have build error that states: "ld: warning: Could not find or use auto-linked library 'swiftCoreFoundation'" This is because Adobe Experience Platform SDK now requires the app uses swift interfaces. Add a dummy .swift file to your project to embed the swift standard libs. See the SampleApp presented in this repo for example.

Android:
Java:
//MainApplication.java
import com.adobe.marketing.mobile.AdobeCallback;
import com.adobe.marketing.mobile.Extension;
import com.adobe.marketing.mobile.LoggingMode;
import com.adobe.marketing.mobile.MobileCore;
import com.adobe.marketing.mobile.Lifecycle;
import com.adobe.marketing.mobile.Signal;
import com.adobe.marketing.mobile.Edge;
import com.adobe.marketing.mobile.edge.consent.Consent;
...
import android.app.Application;
...
public class MainApplication extends Application implements ReactApplication {
  ...
  @Override
  public void on Create(){
    super.onCreate();
    ...
    MobileCore.setApplication(this);
    MobileCore.setLogLevel(LoggingMode.DEBUG);
    MobileCore.configureWithAppID("yourAppID");
    List<Class<? extends Extension>> extensions = Arrays.asList(
                Lifecycle.EXTENSION,
                Signal.EXTENSION,
                Edge.EXTENSION,
                com.adobe.marketing.mobile.edge.identity.Identity.EXTENSION,
                Consent.EXTENSION);
    MobileCore.registerExtensions(extensions, o -> {
      Log.d(LOG_TAG, "AEP Mobile SDK is initialized");
      MobileCore.lifecycleStart(null);
      //enable this for Lifecycle. See Note for collecting Lifecycle metrics.
    });
  }
}
Kotlin:
 // MainApplication.kt
import com.adobe.marketing.mobile.Edge
import com.adobe.marketing.mobile.Lifecycle
import com.adobe.marketing.mobile.LoggingMode
import com.adobe.marketing.mobile.MobileCore
import com.adobe.marketing.mobile.MobileCore.getApplication
import com.adobe.marketing.mobile.edge.consent.Consent
import com.adobe.marketing.mobile.edge.identity.Identity
// MainApplication.kt
 class MainApplication : Application(), ReactApplication {
   ...
 override fun onCreate() {
    super.onCreate()
    
    MobileCore.setApplication(this);
    MobileCore.setLogLevel(LoggingMode.DEBUG)
    MobileCore.configureWithAppID("YOUR-APP-ID");
    MobileCore.registerExtensions(
      listOf(
        Lifecycle.EXTENSION,
        Edge.EXTENSION,
        Identity.EXTENSION,
        Consent.EXTENSION
      ),
    ) {
      Log.d("MainApp", "Adobe Experience Platform Mobile SDK was initialized")
    }

    SoLoader.init(this, false)
    if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
      // If you opted-in for the New Architecture, we load the native entry point for this app.
      load()
    }
    ApplicationLifecycleDispatcher.onApplicationCreate(this)
  }
// MainActivity.kt

import android.app.Activity
import android.app.Application.ActivityLifecycleCallbacks
import com.adobe.marketing.mobile.MobileCore

// Implementing global lifecycle callbacks
override fun onCreate(savedInstanceState: Bundle?) {
    // Set the theme to AppTheme BEFORE onCreate to support
    // coloring the background, status bar, and navigation bar.
    // This is required for expo-splash-screen.
    setTheme(R.style.AppTheme);
    super.onCreate(null)

    application.registerActivityLifecycleCallbacks(object : ActivityLifecycleCallbacks {
        override fun onActivityResumed(activity: Activity) {
            MobileCore.setApplication(application)
            MobileCore.lifecycleStart(null)
        }

        override fun onActivityPaused(activity: Activity) {
            MobileCore.lifecyclePause()
        }

        // the following methods aren't needed for our lifecycle purposes, but are
        // required to be implemented by the ActivityLifecycleCallbacks object
        override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) {}
        override fun onActivityStarted(activity: Activity) {}
        override fun onActivityStopped(activity: Activity) {}
        override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle) {}
        override fun onActivityDestroyed(activity: Activity) {}
    })
  }

For further details on Lifecycle implementation, please refer to the Lifecycle API documentation.

Migration guide

See migration.md for guidance on migrating from ACP React Native libraries.

Troubleshooting and Known issues

  1. Getting error when building on iOS Xcode
Use of '@import' when C++ modules are disabled, consider using -fmodules and -fcxx-modules

Refer to the solution here.

  1. Getting error when building on iOS
Underlying Objective-C module 'AEPRulesEngine' not found

Refer to the solution here.

Contributing

Contributions are welcomed! See CONTRIBUTING and development.md guides for more information.

Licensing

This project is licensed under the Apache V2 License. See LICENSE for more information.