與Adobe Experience Platform Mobile SDK的即時活動整合 mobile-live-config-sdk

在此頁面上:​將Adobe Experience Platform Mobile SDK整合至您的iOS應用程式,以便它在鎖定畫面和Dynamic Island上註冊、顯示及接收即時「即時」活動更新。

Adobe Experience Platform Mobile SDK為Apple的Live活動提供內建支援。 這可讓您的應用程式直接在鎖定畫面和動態島上顯示即時動態更新,而不需開啟應用程式。

  1. 匯入必要的模組

    匯入下列模組: AEPMessaging、AEPMessagingLiveActivity、ActivityKit。

  2. 定義屬性

    符合LiveActivityAttributes,包含LiveActivityData和ContentState屬性。

  3. 註冊即時活動

    在SDK初始化之後使用Messaging.registerLiveActivity()。

  4. 建立Widget設定

    針對鎖定畫面和動態島介面實作ActivityConfiguration。

  5. 在本機開始上線活動(可選)

    您可以透過Journey Optimizer從遠端或在應用程式程式碼內的本機方式起始上線活動。

  6. 新增偵錯支援(選擇性)

    實作Assurance的LiveActivityAssuranceDebuggable。

確認已安裝下列最低版本,以確保組態和相容性正確無誤。

必要條件:

  • iOS:

    • iOS16.1或更新版本:基本上線活動功能
    • iOS 17.2+:推送至啟動支援
    • iOS 18+:廣播頻道支援
  • Xcode: 14.0或更新版本

  • Swift: 5.7或更新版本

  • 相依性: AEPCore、AEPMessaging、AEPMessagingLiveActivity、ActivityKit

  • AEP Mobile SDK版本: iOS Messaging 5.11.0或更新版本

步驟1:匯入必要的模組 import

若要開始,您必須先匯入下列模組: AEPMessaging、AEPMessagingLiveActivity、ActivityKit。

import AEPMessaging
import AEPMessagingLiveActivity
import ActivityKit

步驟2:定義您的已上線活動屬性 attributes

建立符合LiveActivityAttributes通訊協定的結構。 這會定義您的即時活動的靜態資料和動態內容狀態。

主要元件包括:

  • 包含Adobe Experience Platform特定資料的​liveActivityData (必要)。

    • 個別使用者:使用LiveActivityData(liveActivityID: "unique-id")
    • 廣播:使用LiveActivityData(channelID: "channel-id")
  • 靜態屬性、使用案例專屬的自訂屬性,例如restaurantName。

  • ContentState​定義可在上線活動生命週期期間更新的動態資料。 它必須符合Codable和Hashable。

  • LiveActivityOrigin列舉會指定活動是在應用程式內本機起始,還是透過推播開始通知從遠端起始(iOS 17.2和更新版本支援)。 此值可讓SDK在資料收集期間區分本機啟動與遠端觸發的即時活動。

範例

@available(iOS 16.1, *)
struct FoodDeliveryLiveActivityAttributes: LiveActivityAttributes {
    // Mandatory: AEP Integration Data
    var liveActivityData: LiveActivityData

    // Static Attributes: Custom properties that do not change
    var restaurantName: String

    // Dynamic Content State: Data that can be updated
    struct ContentState: Codable, Hashable {
        var orderStatus: String
    }
}
@available(iOS 16.1, *)
public struct LiveActivityData: Codable {
    /// Unique identifier for broadcast Live activity channels
    public let channelID: String?

    /// Unique identifier for individual Live activity
    public let liveActivityID: String?

    /// Indicates local vs remote creation
    public let origin: LiveActivityOrigin?

    // Initializers
    public init(channelID: String)        // For broadcast Live activity
    public init(liveActivityID: String)   // For individual Live activity
}

您也可以為應用程式註冊多個Live活動型別:

if #available(iOS 16.1, *) {
    Messaging.registerLiveActivity(AirplaneTrackingAttributes.self)
    Messaging.registerLiveActivity(FoodDeliveryLiveActivityAttributes.self)
    Messaging.registerLiveActivity(GameScoreLiveActivityAttributes.self)
}

步驟3:註冊即時活動 register

在SDK初始化後,在您的AppDelegate中註冊您的Live活動型別,這可讓您:

  • 啟用自動推播開始權杖集合(iOS 17.2+)
  • 自動收集即時活動更新權杖
  • 啟用生命週期管理和事件追蹤

食品配送即時活動的範例:

if #available(iOS 16.1, *) {
    Messaging.registerLiveActivity(FoodDeliveryLiveActivityAttributes.self)
}

步驟4:建立即時活動Widget widgets

即時活動會透過Widget顯示。 您需要建立Widget套件組合和設定:

食品配送即時活動的範例:

@main
struct FoodDeliveryWidgetBundle: WidgetBundle {
    var body: some Widget {
        FoodDeliveryLiveActivityWidget()
    }
}

@available(iOS 16.1, *)
struct FoodDeliveryLiveActivityWidget: Widget {
    var body: some WidgetConfiguration {
        ActivityConfiguration(for: FoodDeliveryLiveActivityAttributes.self) { context in
            // Lock Screen UI
            VStack {
                Text("Order from \(context.attributes.restaurantName)")
                Text("Status: \(context.state.orderStatus)") // possible status may include "Ordered", "Order accepted", "Preparing", "On the Way","Delivered"
            }
        } dynamicIsland: { context in
            // Dynamic Island UI
            DynamicIsland {
                // Expanded UI
            } compactLeading: {
                // Compact leading UI
            } compactTrailing: {
                // Compact trailing UI
            } minimal: {
                // Minimal UI
            }
        }
    }
}

步驟5:在本機啟動已上線的活動(選用) local

雖然Journey Optimizer可以從遠端啟動即時活動,但您也可以從本機啟動活動:

食品配送即時活動的範例:

let attributes = FoodDeliveryLiveActivityAttributes(
    liveActivityData: LiveActivityData(liveActivityID: "order123"),
    restaurantName: "Pizza Palace"
)

let contentState = FoodDeliveryLiveActivityAttributes.ContentState(
    orderStatus: "Ordered"
)

let activity = try Activity<FoodDeliveryLiveActivityAttributes>.request(
    attributes: attributes,
    contentState: contentState,
    pushType: .token
)

步驟6:新增偵錯支援(選用) debug

如有需要,您可以在Adobe Assurance中偵錯即時活動結構描述:

食品配送即時活動的範例:

@available(iOS 16.1, *)
extension FoodDeliveryLiveActivityAttributes: LiveActivityAssuranceDebuggable {
    static func getDebugInfo() -> (attributes: FoodDeliveryLiveActivityAttributes, state: ContentState) {
        return (
            FoodDeliveryLiveActivityAttributes(
                liveActivityData: LiveActivityData(liveActivityID: "debug-order-123"),
                restaurantName: "Debug Restaurant"
            ),
            ContentState(orderStatus: "Ordered")
        )
    }
}

其他資源

如需全面的SDK檔案與實作詳細資料:

TIP
如果您遇到權杖註冊、裝載對齊或即時活動傳遞的問題,請參閱疑難排解即時活動以取得詳細的偵錯指南。
AI Knowledge Reference

This section contains structured knowledge intended to support interpretation, retrieval, and question answering related to this topic.

For complete understanding, this information should be combined with the documentation on this page. Neither source is intended to stand alone; the page describes the feature, while this section provides additional context that helps disambiguate terminology, intent, applicability, and constraints.

  • TL;DR: This page explains how to integrate the Adobe Experience Platform Mobile SDK into an iOS app so it can register, display, and receive real-time Live activity updates on the Lock Screen and Dynamic Island.

Intents:

  • Import the required modules AEPMessaging, AEPMessagingLiveActivity, and ActivityKit
  • Define Live activity attributes conforming to LiveActivityAttributes, including LiveActivityData and a ContentState
  • Register Live activity types with Messaging.registerLiveActivity() after SDK initialization
  • Create a widget configuration (ActivityConfiguration) for both the Lock Screen and Dynamic Island
  • Optionally start a Live activity locally and add Assurance debug support

Glossary:

  • LiveActivityAttributes: The protocol a struct conforms to, defining both the static data and the dynamic content state for a Live activity (product-specific)
  • LiveActivityData: A required property containing Adobe Experience Platform-specific data; liveActivityID for individual users, channelID for broadcast (product-specific)
  • ContentState: Dynamic data that can be updated during the Live activity lifecycle; must conform to Codable and Hashable
  • LiveActivityOrigin: An enumeration specifying whether an activity was initiated locally or remotely via a push-to-start notification, supported in iOS 17.2 and later (product-specific)
  • Messaging.registerLiveActivity(): The call used after SDK initialization to register Live activity types (product-specific)
  • ActivityConfiguration: The widget configuration implemented for the Lock Screen and Dynamic Island interface
  • LiveActivityAssuranceDebuggable: The protocol implemented to debug Live activity schemas in Adobe Assurance (product-specific)

Guardrails:

  • iOS: 16.1 or later for basic Live activity functionality; 17.2 or later for push-to-start; 18 or later for broadcast channel support (minimum versions).
  • Xcode 14.0 or later (minimum version).
  • Swift 5.7 or later (minimum version).
  • AEP Mobile SDK: iOS Messaging 5.11.0 or later (minimum version).
  • Required dependencies: AEPCore, AEPMessaging, AEPMessagingLiveActivity, ActivityKit.
  • liveActivityData is required and contains Adobe Experience Platform-specific data; ContentState must conform to Codable and Hashable.

Terminology:

  • Canonical name: Adobe Experience Platform Mobile SDK — Acronym: AEP Mobile SDK — variants: Mobile SDK, messaging SDK
  • Synonyms: “push-to-start” = “remotely triggered start, supported in iOS 17.2 and later”
  • Do not confuse: “liveActivityID” (individual users) ≠ “channelID” (broadcast)
  • Do not confuse: “start a Live activity locally” (initiated within the application code) ≠ “start remotely via push-to-start” (triggered remotely through Journey Optimizer)

FAQ:

  • Q: Which modules must I import? — AEPMessaging, AEPMessagingLiveActivity, and ActivityKit.
  • Q: What is the minimum iOS version? — iOS 16.1 or later for basic functionality; iOS 17.2 or later for push-to-start; iOS 18 or later for broadcast channel support.
  • Q: Which AEP Mobile SDK version is required? — iOS Messaging 5.11.0 or later.
  • Q: How do I register Live activity types? — Use Messaging.registerLiveActivity() in your AppDelegate after SDK initialization; you can register multiple Live activity types.
  • Q: Can I start a Live activity without Journey Optimizer? — Yes, a Live activity can be initiated locally within the application code (optional), in addition to being started remotely through Journey Optimizer.
recommendation-more-help
journey-optimizer-help