Show Menu
TOPICS×

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.
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 .

Getting started

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:
  1. Drag the AdobeMobileLibrary folder into your project.
  2. Ensure that the ADBMobileConfig.json file is a member of the containing app’s target.
  3. 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
  4. In your class that implements the UIApplicationDelegate protocol, add the WCSessionDelegate protocol.
    #import <WatchConnectivity/WatchConnectivity.h> 
    @interface AppDelegate : UIResponder <UIApplicationDelegate, WCSessionDelegate>
    
    
  5. In the implementation file of your app delegate class, import the AdobeMobileLibrary .
    #import “ADBMobile.h”
    
    
  6. Before making a call to the ADBMobile library, in application:didFinishLaunchingWithOptions: of your app delegate, configure your WCSession .
    // check for session availability 
    if ([WCSession isSupported]) { 
        WCSession *session = [WCSession defaultSession]; 
        session.delegate = self; 
        [session activateSession]; 
    }
    
    
  7. In your app delegate, implement the session:didReceiveMessage: and session:didReceiveUserInfo: methods.
    syncSettings: is called in the ADBMobile library, which returns a bool that indicates whether the dictionary was meant for consumption by the ADBMobile library. If it returns No , 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

  1. Ensure that the ADBMobileConfig.json file is a member of your WatchKit extension’s target.
  2. 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
  3. In your class that implements the WKExtensionDelegate protocol, import WatchConnectivity and add the WCSessionDelegate protocol.
    #import <WatchConnectivity/WatchConnectivity.h> 
    @interface ExtensionDelegate : NSObject <WKExtensionDelegate, WCSessionDelegate>
    
    
  4. In the implementation file of your extension delegate class, import the AdobeMobileLibrary .
    #import “ADBMobile.h”
    
    
  5. In applicationDidFinishLaunching of your extension delegate, configure your WCSession before making any calls to the ADBMobile library.
    // check for session availability 
    if ([WCSession isSupported]) { 
        WCSession *session = [WCSession defaultSession]; 
        session.delegate = self; 
        [session activateSession]; 
    }
    
    
  6. In applicationDidFinishLaunching of your extension delegate, initialize the watch app for the SDK.
    [ADBMobile initializeWatch];
    
    
  7. In your extension delegate, implement the session:didReceiveMessage: and session:didReceiveUserInfo: methods.
    syncSettings: is called in the ADBMobile library, which returns a bool that indicates whether the dictionary was meant for consumption by the ADBMobile library. If it returns NO , 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 to Extension .
  • 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.