安装 Adobe Experience Platform Mobile SDK
创建对象:
- 初学者
- 中级
- 开发人员
了解如何在移动应用程序中实施 Adobe Experience Platform Mobile SDK。
先决条件
- 已成功使用上一课程中描述的扩展生成标记库。
- 来自移动设备安装说明的开发环境文件ID。
- 已下载iOS的示例应用程序或Android的示例应用程序。
- 体验Xcode (iOS)或Android Studio (Android)
学习目标
在本课程中,您将执行以下操作:
- 将所需的SDK添加到您的项目中。
- 注册扩展。
Swift包管理器
使用Xcode的原生Swift包管理器添加单个包,而不使用CocoaPods和Pod文件(如生成SDK安装说明中所述)。 Xcode项目已经为您添加了所有包依赖项。 Xcode 包依赖项 屏幕应如下所示:
在Xcode中,您可以使用 文件 > 添加包…… 来添加包。 下表提供了用于添加包的URL的链接。 这些链接还将引导您了解有关每个特定包的更多信息。
AEPCore、AEPServices和AEPIdentity扩展代表Adobe Experience Platform SDK的基础 — 使用SDK的每个应用程序都必须包含它们。 这些模块包含所有SDK扩展都需要的通用功能和服务集。
AEPCore包含事件中心的实现。 事件中心是在应用程序和SDK之间交付事件的机制。 事件中心还用于在扩展之间共享数据。AEPServices提供平台支持所需的多种可重用的实现,包括网络、磁盘访问和数据库管理。AEPIdentity实现与Adobe Experience Platform Identity服务的集成。AEPSignal表示Adobe Experience Platform SDK Signal扩展,该扩展允许营销人员向其应用程序发送“信号”,以将数据发送到外部目标或打开URL。AEPLifecycle表示Adobe Experience Platform SDK生命周期扩展,该扩展可帮助收集应用程序生命周期量度,如应用程序安装或升级信息、应用程序启动和会话信息、设备信息以及应用程序开发人员提供的任何其他上下文数据。
AEPEdge)允许您从移动应用程序向Adobe Edge Network发送数据。 通过此扩展,您可以更稳健地实施Adobe Experience Cloud功能,通过一个网络调用提供多个Adobe解决方案,同时将此信息转发到Adobe Experience Platform。Edge Network移动扩展是Adobe Experience Platform SDK的扩展。 该扩展需要
AEPCore和AEPServices扩展才能进行事件处理,需要AEPEdgeIdentity扩展才能检索身份,如ECID。AEPEdgeIdentity)在使用Adobe Experience Platform SDK和Edge Network扩展时,允许处理来自移动应用程序的用户身份数据。AEPConsent)在使用Adobe Experience Platform SDK和Edge Network扩展时允许从移动应用程序收集同意首选项。AEPUserProfile)是管理Adobe Experience Platform SDK的用户配置文件的扩展。AEPPlaces)允许您跟踪Adobe Places界面和Adobe数据收集标记规则中定义的地理位置事件。AEPMessaging)允许您将推送通知令牌和推送通知点进反馈发送到Adobe Experience Platform。AEPOptimize)提供了API,以使用Adobe Target或Adobe Journey Optimizer Offer Decisioning在Adobe Experience Platform Mobile SDK中启用实时个性化工作流。 它需要AEPCore和AEPEdge扩展才能将个性化查询事件发送到Experience Edge Network。导入扩展
在Xcode中打开示例应用程序的 开始 文件夹中的项目。
在Xcode中,导航到 Luma > Luma > AppDelegate,并确保以下导入是此源文件的一部分。
// import AEP MobileSDK libraries
import AEPCore
import AEPServices
import AEPIdentity
import AEPSignal
import AEPLifecycle
import AEPEdge
import AEPEdgeIdentity
import AEPEdgeConsent
import AEPUserProfile
import AEPPlaces
import AEPMessaging
import AEPOptimize
import AEPAssurance
对 Luma > Luma > Utils > MobileSDK 执行相同操作。
更新AppDelegate
在Xcode项目导航器中导航到 Luma > Luma > AppDelegate。
-
将
@AppStorage的YOUR_ENVIRONMENT_ID_GOES_HERE值environmentFileId替换为您从生成SDK安装说明中的标记检索到的环境文件ID值。@AppStorage("environmentFileId") private var environmentFileId = "YOUR_ENVIRONMENT_ID_GOES_HERE" -
将以下代码添加到
application(_, didFinishLaunchingWithOptions)函数。// Define extensions let extensions = [ AEPIdentity.Identity.self, Lifecycle.self, Signal.self, Edge.self, AEPEdgeIdentity.Identity.self, Consent.self, UserProfile.self, Places.self, Messaging.self, Optimize.self, Assurance.self ] // Register extensions MobileCore.registerExtensions(extensions, { // Use the environment file id assigned to this application via Adobe Experience Platform Data Collection Logger.aepMobileSDK.info("Luma - using mobile config: \(self.environmentFileId)") MobileCore.configureWith(appId: self.environmentFileId) // set this to false or comment it when deploying to TestFlight (default is false), // set this to true when testing on your device. MobileCore.updateConfigurationWith(configDict: ["messaging.useSandbox": true]) if appState != .background { // only start lifecycle if the application is not in the background MobileCore.lifecycleStart(additionalContextData: nil) } // assume unknown, adapt to your needs. MobileCore.setPrivacyStatus(.unknown) })
上述代码执行以下操作:
- 注册所需的扩展。
- 配置MobileCore和其他扩展以使用标记属性配置。
- 启用调试日志记录。 有关更多详细信息和选项,请参阅Adobe Experience Platform Mobile SDK文档。
- 启动生命周期监控。 有关更多详细信息,请参阅本教程中的生命周期步骤。
- 将默认同意设置为“未知”。 有关更多详细信息,请参阅教程中的同意步骤。
确保基于您为了(开发、暂存或生产)构建的标记环境中的MobileCore.configureWith(appId: self.environmentFileId),使用appId更新environmentFileId。
Gradle
您使用生成SDK安装说明中的依赖项通过Gradle与Android Studio的集成来添加单个包,Android Studio项目已经为您添加了所有包依赖项。
-
选择
作为工具。 -
选择 Android 视图。
-
从左窗格中选择 Gradle脚本 > build.gradle.kts (模块:app)。 然后,在右侧窗格中,滚动直到看到
dependencies为止。
在Android Studio中,您可以使用 文件 > 项目结构…… 来添加模块依赖项。 选择 依赖项,然后使用 模块
com.adobe.
marketing.mobile:
MobileCore和Identity扩展代表Adobe Experience Platform SDK的基础。 使用SDK的每个应用程序都必须包含这些变量。 这些模块包含所有SDK扩展都需要的通用功能和服务集。
MobileCore包含事件中心的实现。 事件中心是在应用程序和SDK之间交付事件的机制。 事件中心还用于在扩展之间共享数据,并提供平台支持所需的多种可重用实施,包括联网、磁盘访问和数据库管理。Identity实现与Adobe Experience Platform Identity服务的集成。Signal表示Adobe Experience Platform SDK的Signal扩展,该扩展允许营销人员向其应用程序发送“信号”,以将数据发送到外部目标或打开URL。Lifecycle表示Adobe Experience Platform SDK的生命周期扩展,该扩展可帮助收集应用程序生命周期量度,如应用程序安装或升级信息、应用程序启动和会话信息、设备信息以及应用程序开发人员提供的任何其他上下文数据。
AEPEdge)允许您从移动应用程序向Adobe Edge Network发送数据。 通过此扩展,您可以更稳健地实施Adobe Experience Cloud功能,通过一个网络调用提供多个Adobe解决方案,同时将此信息转发到Adobe Experience Platform。Edge Network移动扩展是Adobe Experience Platform SDK的扩展。 该扩展需要
Mobile Core和Services扩展才能进行事件处理。 以及用于检索身份的Identity for Edge Network扩展,如ECID。此服务是Android 2.x Adobe Experience Platform SDK的Places移动扩展,需要核心扩展才能进行事件处理。
导入扩展
在Android Studio中,导航到 应用程序 > kotlin+java > com.adobe.luma.tutorial.android > LumaApplication,并确保源文件中包含下列导入。
import com.adobe.marketing.mobile.Assurance
import com.adobe.marketing.mobile.Edge
import com.adobe.marketing.mobile.Lifecycle
import com.adobe.marketing.mobile.LoggingMode
import com.adobe.marketing.mobile.Messaging
import com.adobe.marketing.mobile.MobileCore
import com.adobe.marketing.mobile.MobilePrivacyStatus
import com.adobe.marketing.mobile.Places
import com.adobe.marketing.mobile.Signal
import com.adobe.marketing.mobile.UserProfile
import com.adobe.marketing.mobile.edge.consent.Consent
import com.adobe.marketing.mobile.edge.identity.Identity
import com.adobe.marketing.mobile.optimize.Optimize
对 应用程序 > kotlin+java > com.adobe.luma.tutorial.android > 模型 > MobileSDK 执行相同的操作。
更新LumaApplication
在 Android 视图中,导航到Android Studio中的 应用程序 > kotlin+java > com.adobe.luma.tutorial.android > LumaApplication。
-
将
"YOUR_ENVIRONMENT_FILE_ID"中的private var environmentFileId = "YOUR_ENVIRONMENT_ID_GOES_HERE"替换为您从生成SDK安装说明中的标记检索到的环境文件ID值。private var environmentFileId = "YOUR_ENVIRONMENT_ID_GOES_HERE" -
将以下代码添加到
override fun onCreate()中的class LumaApplication : Application()函数。// Define extensions val extensions = listOf( Identity.EXTENSION, Lifecycle.EXTENSION, Signal.EXTENSION, Edge.EXTENSION, Consent.EXTENSION, UserProfile.EXTENSION, Places.EXTENSION, Messaging.EXTENSION, Optimize.EXTENSION, Assurance.EXTENSION ) // Register extensions MobileCore.registerExtensions(extensions) { // Use the environment file id assigned to this application via Adobe Experience Platform Data Collection Log.i("Luma", "Using mobile config: $environmentFileId") MobileCore.configureWithAppID(environmentFileId) // set this to true when testing on your device, default is false. //MobileCore.updateConfiguration(mapOf("messaging.useSandbox" to true)) // assume unknown, adapt to your needs. MobileCore.setPrivacyStatus(MobilePrivacyStatus.UNKNOWN) }上述代码执行以下操作:
- 注册所需的扩展。
- 配置MobileCore和其他扩展以使用标记属性配置。
- 启用调试日志记录。 有关更多详细信息和选项,请参阅Adobe Experience Platform Mobile SDK文档。
- 启动生命周期监控。 有关更多详细信息,请参阅本教程中的生命周期步骤。
- 将默认同意设置为“未知”。 有关更多详细信息,请参阅教程中的同意步骤。
确保根据您为了(开发、暂存或生产)构建的标记环境中的环境文件ID,使用MobileCore.configureWith(environmentFileId)更新environmentFileId。
下一步:设置Assurance