RNSelligent 4.0.0

RNSelligent 4.0.0

Selligent Marketing Cloud 维护。



  • 名称

SelligentMobileSDK-ReactNative (selligent-react-native)

此模块提供了一个用于在 React Native 中使用 Selligent 移动 SDK 的 API。

SelligentMobileSDK-ReactNative 集成

此模块支持以下 SDK 和工具

重要 目前此模块不支持 REACT NATIVE 的新架构!以下库包含 React native 模块,这些模块针对 React Native 的旧架构量身定制,并且仅能在 React Native 的旧架构中使用,当新架构稳定后将予以弃用。

SDK 版本
Android SDK 4.3.0
iOS SDK 3.6.1
ReactNative 0.71.8
Expo SDK 48

安装

请在安装后参阅我们的 SDK 完整文档,了解如何使用 SDK 的分步指南。

  1. 安装模块

    npm install @selligent-marketing-cloud/selligent-react-native --save
  2. 在 React Native 项目的根目录中创建一个 selligent.json 文件(名称区分大小写)并包含以下内容

    {
      "url": "someMobilePushUrl",
      "clientId": "someClientId",
      "privateKey": "somePrivateKey",
      "fullyQualifiedNotificationActivityClassName": "com.some.project.MainActivity",
      "delayedPushAction": true
    }

检查我们SDK完整文档中可以使用的所有选项。

Android特定安装

重要: 由于本模块2.6.0版本起,我们要求您的应用程序使用版本4.2.0或更高版本的Android Gradle插件才能构建到Android平台上。这是React Native版本0.64.0及以后默认的Android Gradle插件版本,但在较旧版本的React Native中可以手动提升。

针对华为开发者注意!

为了在华为设备上使用本模块(不包含Goggle Play服务),您应该在您的React Native项目的Android项目build.gradle文件中添加以下依赖。

在您的Android项目根build.gradle文件中

buildscript {
 repositories {
  maven { url 'https://developer.huawei.com/repo/' }
 }
 dependencies {
  classpath 'com.huawei.agconnect:agcp:1.6.0.300'
 }
}

allProjects: {
  repositories: {
    maven { url 'https://developer.huawei.com/repo/' }
  }
}

在您应用程序模块的build.gradle文件中

apply plugin: 'com.huawei.agconnect'

dependencies {
  api 'com.huawei.hms:base:6.2.0.300'
  api 'com.huawei.hms:push:6.1.0.300'
  api 'com.huawei.hms:maps:6.2.0.301'
}
(对于不使用自动链接的RN 0.59及以下版本)
  1. 按照本机文档部分创建Google应用程序,并将google-services.json文件放入./android/app文件夹中。

  2. android/settings.gradle文件的末尾添加以下行

    include ':selligent-react-native'
    project(':selligent-react-native').projectDir = new File(rootProject.projectDir, '../node_modules/@selligent-marketing-cloud/selligent-react-native/android')
  3. android/build.gradle文件中添加以下内容,并确保android/gradle/wrapper/gradle-wrapper.properties中的Gradle版本为>= 6.7.1

    // android/build.gradle
    
    buildscript {
        dependencies {
            // Make sure your Gradle plugin version is >= 4.2.0
            classpath("com.android.tools.build:gradle:4.2.0")
            // Add the following:
            classpath 'com.google.gms:google-services:4.3.3'
        }
    }
     // android/gradle/wrapper/gradle-wrapper.properties
     distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip
  4. android/app/build.gradle文件中添加以下内容

    dependencies {
        // Add the following:
        compile project(path: ':selligent-react-native')
    }
    // Add the following:
    apply plugin: 'com.google.gms.google-services'
  5. android/app/src/../MainApplication.java文件中添加以下内容

    // Add the following import statements:
    import com.selligent.RNSelligent;
    import com.selligent.RNSelligentPackage;
    
    public class MainApplication extends Application implements ReactApplication {
    
        private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
             @Override
             protected List<ReactPackage> getPackages() {
    
                 List<ReactPackage> packages = new PackageList(this).getPackages();
                 // Add the following:
                 packages.add(new RNSelligentPackage());
                 return packages;
             }
        };
    
        @Override
        public void onCreate() {
            super.onCreate();
    
            // Add the following:
            RNSelligent.configure(this);
        }
    }
(对于使用自动链接的RN 0.60及以上版本)
  1. 按照Android - 使用SDK.pdf中的创建Google应用程序部分创建Google应用程序,并将google-services.json文件放入./android/app文件夹中。

  2. android/build.gradle文件中添加以下内容,并确保android/gradle/wrapper/gradle-wrapper.properties中的Gradle版本为>= 6.7.1

    // android/build.gradle 
    
    buildscript {
        dependencies {
            // Add the following:
            classpath 'com.google.gms:google-services:4.3.3'
        }
    }
  3. android/app/build.gradle文件的底部添加以下内容

    // Add the following:
    apply plugin: 'com.google.gms.google-services'
  4. android/app/src/../MainApplication.java文件中添加以下内容

    // Add the following import statements:
    import com.selligent.RNSelligent;
    import com.selligent.RNSelligentPackage;
    
    public class MainApplication extends Application implements ReactApplication {
        @Override
        public void onCreate() {
            super.onCreate();
    
            // Add the following:
            RNSelligent.configure(this);
        }
    }

针对iOS的特定安装

(对于不使用自动链接的RN 0.59及以下版本)
  1. node_modules/@selligent-marketing-cloud/selligent-react-native/ios 文件夹复制到 Xcode 项目 中。将其拖放到 Libraries 文件夹下。这将把模块链接到 iOS 项目中。

  2. 将您在根目录中创建的 selligent.json 文件拖放到 Xcode 项目内的 Copy Bundle Resources 选项,位于目标的 Build phases 下。

    不要勾选“如果需要则复制”选项,以确保您只需要管理一个 selligent.json 文件。

  3. 在您的 Podfile 中添加原生 iOS SDK 依赖项:s.dependency "SelligentMobileSDK/Framework", "3.6.1" 或从以下链接手动下载它:[这里](https://github.com/SelligentMarketingCloud/MobileSDK-iOS/tree/master/Framework) 并将其拖放到您的 Xcode 项目 中。

  4. /ios 文件夹中执行 pod install

  5. 从现在开始,打开 .xcworkspace 文件以在 Xcode 中进行更改。

  6. AppDelegate.mm 文件中的 application:didFinishLaunchingWithOptions: 方法中初始化 SDK。

    @import RNSelligentMobileSDK;
    
    // You can alternatively specify a different file name (without the extension) from where to load the Selligent configs (defaults to 'selligent')
    // if (!launchOptions) {
    //    launchOptions = [NSMutableDictionary new];
    // }
    // [launchOptions setValue:@"alternativeFileName" forKey:@"RN_SELLIGENT_JSON"];
    
    [RNSelligent configureWithLaunchOptions:launchOptions];
(对于使用自动链接的RN 0.60及以上版本)
  1. 将您在根目录中创建的 selligent.json 文件拖放到 Xcode 项目内的 Copy Bundle Resources 选项,位于目标的 Build phases 下。

    不要勾选“如果需要则复制”选项,以确保您只需要管理一个 selligent.json 文件。

  2. /ios 文件夹中执行 pod install

  3. AppDelegate.m 文件中的 application:didFinishLaunchingWithOptions: 方法中导入并初始化 SDK(在方法末尾放置它)。

    @import RNSelligentMobileSDK;
    // OR
    // #import <RNSelligentMobileSDK/RNSelligentMobileSDK-Swift.h>
    
    // At the end of application:didFinishLaunchingWithOptions:
    [RNSelligent configureWithLaunchOptions:launchOptions];