從 WatchOS 2 開始,您的 WatchKit 延伸功能可在 Apple Watch 上執行。在此環境中執行的應用程式皆須使用 WatchConnectivity
架構,以與其容納 iOS 應用程式共用資料。
從 AdobeMobileLibrary
4.6.0 版開始,即支援 WatchConnectivity
。
在尋找 Adobe Experience Platform Mobile SDK 的相關資訊和文件嗎?按一下這裡以取得最新文件。
我們於 2018 年 9 月發行了全新的 SDK 主要版本。這些新的 Adobe Experience Platform Mobile SDK 可透過 Experience Platform Launch 設定。
確保您擁有至少具備以下目標的專案:
如需有關開發 WatchKit 應用程式的詳細資訊,請參閱 Watch 應用程式架構。
在您的 Xcode 專案中完成以下步驟:
將 AdobeMobileLibrary
資料夾拖曳到專案中。
確認 ADBMobileConfig.json
檔案為容納應用程式目標的成員。
在容納應用程式目標的「建立階段」標籤中,展開「連結二進位檔與資料庫」區段,然後新增下列資料庫:
AdobeMobileLibrary.a
libsqlite3.tbd
SystemConfiguration.framework
在實施 UIApplicationDelegate
通訊協定的類別中,新增 WCSessionDelegate
通訊協定。
#import <WatchConnectivity/WatchConnectivity.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate, WCSessionDelegate>
在應用程式委派類別的實施檔案中,匯入 AdobeMobileLibrary
。
#import “ADBMobile.h”
呼叫 ADBMobile
資料庫之前,請在應用程式委派的 application:didFinishLaunchingWithOptions:
中,設定您的 WCSession
。
// check for session availability
if ([WCSession isSupported]) {
WCSession *session = [WCSession defaultSession];
session.delegate = self;
[session activateSession];
}
在您的應用程式委派中,實施 session:didReceiveMessage:
和 session:didReceiveUserInfo:
方法。
系統會在 ADBMobile
資料庫中呼叫 syncSettings:
,其會傳回布林值指示是否會由 ADBMobile
資料庫使用字典。如果其傳回 No
,則訊息不會從 Adobe SDK 啟動。
- (void) session:(WCSession *)session didReceiveMessage:(NSDictionary<NSString *,id> *)message {
// pass message to ADBMobile
if (![ADBMobile syncSettings:message]) {
// handle your own custom messages
}
}
- (void) session:(WCSession *)session didReceiveUserInfo:(NSDictionary<NSString *,id> *)userInfo {
// pass userInfo to ADBMobile
if (![ADBMobile syncSettings:userInfo]) {
// handle your own custom messages
}
}
確認 ADBMobileConfig.json
檔案為 WatchKit 延伸功能目標的成員。
在 WatchKit 延伸功能目標的「建立階段」標籤中,展開「連結二進位檔與資料庫」區段,然後新增下列資料庫:
AdobeMobileLibrary_Watch.a
libsqlite3.tbd
在實施 WKExtensionDelegate
通訊協定的類別中,匯入 WatchConnectivity
並新增 WCSessionDelegate
通訊協定。
#import <WatchConnectivity/WatchConnectivity.h>
@interface ExtensionDelegate : NSObject <WKExtensionDelegate, WCSessionDelegate>
在延伸功能委派類別的實施檔案中,匯入 AdobeMobileLibrary
。
#import “ADBMobile.h”
在延伸功能委派的 applicationDidFinishLaunching
中,設定您的 WCSession
,然後再對 ADBMobile
資料庫進行任何呼叫。
// check for session availability
if ([WCSession isSupported]) {
WCSession *session = [WCSession defaultSession];
session.delegate = self;
[session activateSession];
}
在延伸功能委派的 applicationDidFinishLaunching
中,初始化 SDK 的 Watch 應用程式。
[ADBMobile initializeWatch];
在您的延伸功能委派中,實施 session:didReceiveMessage:
和 session:didReceiveUserInfo:
方法。
系統會在 ADBMobile
資料庫中呼叫 syncSettings:
,其會傳回布林值指示是否會由 ADBMobile
資料庫使用字典。如果其傳回 NO
,則訊息不會從 Adobe SDK 啟動。
- (void) session:(WCSession *)session didReceiveMessage:(NSDictionary<NSString *,id> *)message {
// pass message to ADBMobile
if (![ADBMobile syncSettings:message]) {
// handle your own custom messages
}
}
- (void) session:(WCSession *)session didReceiveUserInfo:(NSDictionary<NSString *,id> *)userInfo {
// pass userInfo to ADBMobile
if (![ADBMobile syncSettings:userInfo]) {
// handle your own custom messages
}
}
請記住以下資訊:
a.RunMode
則會設為 Extension
。a.AppID
中正確回報其名稱。