@adobe/react-native-aepmessaging 中文文档教程

发布于 3年前 浏览 2 项目主页 更新于 3年前

React Native Adobe Experience Platform Messaging Extension

npm 版本npm downloads

@adobe/react-native-aepmessaging 是 iOS 和 Android Adobe Journey Optimizer Messaging 允许与 React Native 应用程序集成。

Prerequisites

消息传递扩展具有以下对等依赖项,必须在安装消息传递扩展之前安装它们:

Installation

请参阅要求和安装 主页上的说明

安装 @adobe/react-native-aepmessaging 包:

cd MyReactApp
npm install @adobe/react-native-aepmessaging

Usage

Messaging

Installing and registering the extension with the AEP Mobile Core

Initialization

初始化 SDK 应该在本机代码中完成,可以找到有关如何初始化 SDK 的其他文档 此处

示例:

iOS

@import AEPCore;
@import AEPLifecycle;
@import AEPEdge;
@import AEPEdgeIdentity;
@import AEPMessaging;
...
@implementation AppDelegate
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  [AEPMobileCore setLogLevel: AEPLogLevelDebug];
  [AEPMobileCore configureWithAppId:@"yourAppID"];
  [AEPMobileCore registerExtensions: @[AEPMobileEdge.class, AEPMobileEdgeIdentity.class, AEPMobileMessaging.class] completion:^{
    [AEPMobileCore lifecycleStart:@{@"contextDataKey": @"contextDataVal"}];
  }
  ];

  return YES;
}

@end

Android

import com.adobe.marketing.mobile.AdobeCallback;
import com.adobe.marketing.mobile.InvalidInitException;
import com.adobe.marketing.mobile.Lifecycle;
import com.adobe.marketing.mobile.LoggingMode;
import com.adobe.marketing.mobile.MobileCore;
import com.adobe.marketing.mobile.Edge;
import com.adobe.marketing.mobile.edge.identity;
import com.adobe.marketing.mobile.Messaging;

...
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);
    try {
      Edge.registerExtension();
      Identity.registerExtension();
      Messaging.registerExtension();
      MobileCore.configureWithAppID("yourAppID");
      MobileCore.start(new AdobeCallback() {
        @Override
        public void call(Object o) {
          MobileCore.lifecycleStart(null);
        }
      });
    } catch (InvalidInitException e) {
      ...
    }
  }
}     

Importing the extension:

import {AEPMessaging} from '@adobe/react-native-aepmessaging';

API reference

extensionVersion

语法

extensionVersion(): Promise<string>;

示例

Messaging.extensionVersion().then(version => console.log("AdobeExperienceSDK: Messaging version: " + version));

Configure Adobe Journey Optimizer

要在 Launch 中配置 Adob​​e Journey 优化器消息传递,请按照 配置 Adob​​e Journey 优化器

Push Notification Setup

必须在 React Native 应用程序的本机 (Android/iOS) 代码中处理推送通知. 要在原生项目中配置推送通知,请按照各自平台提供的说明进行操作:

Messaging SDK API usage

Messaging SDK APIs must be called from the native Android/iOS project of React Native app。

iOS API usage
Android API usage

在 Android 中,MessagingPushPayload 可用于获取标题、正文和操作等通知属性。 这些对于创建推送通知很有用。

React Native Adobe Experience Platform Messaging Extension

npm versionnpm downloads

@adobe/react-native-aepmessaging is a wrapper around the iOS and Android Adobe Journey Optimizer Messaging to allow for integration with React Native applications.

Prerequisites

The messaging extension has the following peer dependenices, which must be installed prior to installing the messaging extension:

Installation

See Requirements and Installation instructions on the main page

Install the @adobe/react-native-aepmessaging package:

cd MyReactApp
npm install @adobe/react-native-aepmessaging

Usage

Messaging

Installing and registering the extension with the AEP Mobile Core

Initialization

Initializing the SDK should be done in native code, additional documentation on how to initialize the SDK can be found here.

Example:

iOS

@import AEPCore;
@import AEPLifecycle;
@import AEPEdge;
@import AEPEdgeIdentity;
@import AEPMessaging;
...
@implementation AppDelegate
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  [AEPMobileCore setLogLevel: AEPLogLevelDebug];
  [AEPMobileCore configureWithAppId:@"yourAppID"];
  [AEPMobileCore registerExtensions: @[AEPMobileEdge.class, AEPMobileEdgeIdentity.class, AEPMobileMessaging.class] completion:^{
    [AEPMobileCore lifecycleStart:@{@"contextDataKey": @"contextDataVal"}];
  }
  ];

  return YES;
}

@end

Android

import com.adobe.marketing.mobile.AdobeCallback;
import com.adobe.marketing.mobile.InvalidInitException;
import com.adobe.marketing.mobile.Lifecycle;
import com.adobe.marketing.mobile.LoggingMode;
import com.adobe.marketing.mobile.MobileCore;
import com.adobe.marketing.mobile.Edge;
import com.adobe.marketing.mobile.edge.identity;
import com.adobe.marketing.mobile.Messaging;

...
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);
    try {
      Edge.registerExtension();
      Identity.registerExtension();
      Messaging.registerExtension();
      MobileCore.configureWithAppID("yourAppID");
      MobileCore.start(new AdobeCallback() {
        @Override
        public void call(Object o) {
          MobileCore.lifecycleStart(null);
        }
      });
    } catch (InvalidInitException e) {
      ...
    }
  }
}     

Importing the extension:

import {AEPMessaging} from '@adobe/react-native-aepmessaging';

API reference

extensionVersion

Syntax

extensionVersion(): Promise<string>;

Example

Messaging.extensionVersion().then(version => console.log("AdobeExperienceSDK: Messaging version: " + version));

Configure Adobe Journey Optimizer

To configure Adobe Journey optimizer Messaging in Launch follow steps in Configure Adobe Journey optimizer

Push Notification Setup

Handling push notifications must be done in native (Android/iOS) code for the React Native app. To configure push notification in the native project, follow the instructions provided by their respective platforms:

Messaging SDK API usage

Messaging SDK APIs must be called from the native Android/iOS project of React Native app.

iOS API usage
Android API usage

In Android, MessagingPushPayload can be used for getting the notification attributes like title, body, and action. These are useful for push notification creation.

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文