Apple Watch implementation with WatchOS 2
Starting with WatchOS 2, your WatchKit Extensions can run on an Apple Watch. Applications that run in this environment require the WatchConnectivity
framework to share data with their containing iOS app.
Tip: Starting with
AdobeMobileLibrary
v4.6.0,WatchConnectivity
is supported.
New Adobe Experience Platform Mobile SDK Release
Looking for information and documentation related to the Adobe Experience Platform Mobile SDK? Click here for our latest documentation.
As of September 2018, we released a new, major version of the SDK. These new Adobe Experience Platform Mobile SDKs are configurable through Experience Platform Launch.
- To get started, go to Adobe Experience Platform Launch.
- To see what is in the Experience Platform SDK repositories, go to Github: Adobe Experience Platform SDKs.
Getting started
Important: Ensure that you have a project with at least the following targets:
- The containing app
- The WatchKit app
- The WatchKit extension
For more information about developing WatchKit apps, see The Watch App Architecture.
Configure the containing app
Complete the following steps in your Xcode project:
-
Drag the
AdobeMobileLibrary
folder into your project. -
Ensure that the
ADBMobileConfig.json
file is a member of the containing app’s target. -
In the Build Phases tab of your containing app’s target, expand the Link Binary with Libraries section and add the following libraries:
AdobeMobileLibrary.a
libsqlite3.tbd
SystemConfiguration.framework
-
In your class that implements the
UIApplicationDelegate
protocol, add theWCSessionDelegate
protocol.#import <WatchConnectivity/WatchConnectivity.h> @interface AppDelegate : UIResponder <UIApplicationDelegate, WCSessionDelegate>
-
In the implementation file of your app delegate class, import the
AdobeMobileLibrary
.#import "ADBMobile.h"
-
Before making a call to the
ADBMobile
library, inapplication:didFinishLaunchingWithOptions:
of your app delegate, configure yourWCSession
.// check for session availability if ([WCSession isSupported]) { WCSession *session = [WCSession defaultSession]; session.delegate = self; [session activateSession]; }
-
In your app delegate, implement the
session:didReceiveMessage:
andsession:didReceiveUserInfo:
methods.syncSettings:
is called in theADBMobile
library, which returns a bool that indicates whether the dictionary was meant for consumption by theADBMobile
library. If it returnsNo
, the message was not initiated from the 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 } }
Configure the WatchKit extension
-
Ensure that the
ADBMobileConfig.json
file is a member of your WatchKit extension’s target. -
In the Build Phases tab of your WatchKit extension’s target, expand the Link Binary with Libraries section and add the following libraries:
AdobeMobileLibrary_Watch.a
libsqlite3.tbd
-
In your class that implements the
WKExtensionDelegate
protocol, importWatchConnectivity
and add theWCSessionDelegate
protocol.#import <WatchConnectivity/WatchConnectivity.h> @interface ExtensionDelegate : NSObject <WKExtensionDelegate, WCSessionDelegate>
-
In the implementation file of your extension delegate class, import the
AdobeMobileLibrary
.#import "ADBMobile.h"
-
In
applicationDidFinishLaunching
of your extension delegate, configure yourWCSession
before making any calls to theADBMobile
library.// check for session availability if ([WCSession isSupported]) { WCSession *session = [WCSession defaultSession]; session.delegate = self; [session activateSession]; }
-
In
applicationDidFinishLaunching
of your extension delegate, initialize the watch app for the SDK.[ADBMobile initializeWatch];
-
In your extension delegate, implement the
session:didReceiveMessage:
andsession:didReceiveUserInfo:
methods.syncSettings:
is called in theADBMobile
library, which returns a bool that indicates whether the dictionary was meant for consumption by theADBMobile
library. If it returnsNO
, the message was not initiated from the 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 } }
Additional Information
Remember the following information:
- For WatchKit apps,
a.RunMode
will be set toExtension
. - Because WatchKit apps run on the watch, the apps will correctly report their names in
a.AppID
. - No lifecycle call is triggered on WatchOS2 apps.