watchOS app integration
Integrating Appfigurate Library into watchOS apps
watchOS apps can be developed in both Swift and Objective-C.
Independent watchOS apps are not supported, watchOS apps must be bundled inside a companion iOS app. (The companion iOS app's Appfigurate Library is used to proxy any configuration payloads applied to the watchOS app).
Prerequisites
You must perform the following before starting watchOS native integration:
iOS native app integration of Appfigurate Library.
In addition to the iOS native app integration prerequisites, you must also have:
watchOS SDKs and associated watchOS Simulators.
Use paired iOS and watchOS Simulators.
Appfigurate Simulator app installed into one or more paired iOS Simulators (use the AppfigurateSE macOS app for easy 1 click installation).
Your watchOS app must target watchOS 5.0+ in order to link Appfigurate Library.
Add AppfigurateLibrary.xcframework to the watchOS app target
In Xcode:
Tap on your watchOS app target.
Tap the General tab. Tap the
+button under theFrameworks, Libraries, and Embedded Contentsection.Select
AppfigurateLibrarypackage.
Add new app into Appfigurate Simulator
Run Appfigurate in the paired iOS Simulator.
Tap ≡ YOUR-IOS-APP app. The Edit app screen will be displayed.
Tap Duplicate row row. The Duplicate app screen will be displayed.
Select app type watchOS.
Tap Duplicate.
Share the iOS app APLConfiguration subclass with the watchOS app
Share the iOS app's APLConfiguration subclass with the watchOS app extension.
Open your APLConfiguration subclass (e.g. Configuration.swift/m file) into the Xcode editor. In the Target Membership inspection pane tick on your watchOS app target.
WKApplicationDelegate/WKExtensionDelegate
For watchOS apps using SwiftUI, you must call APLApplicationDidFinishLaunching() in the WKApplicationDelegate's applicationDidFinishLaunching method.
Swift
WKApplicationDelegateexample
import AppfigurateLibrary
...
class MyApplicationDelegate: NSObject, WKApplicationDelegate, ObservableObject {
func applicationDidFinishLaunching() {
APLApplicationDidFinishLaunching()
}
}Ensure you use the WKApplicationDelegateAdaptor property wrapper inside your App declaration to tell SwiftUI about the delegate type:
Swift
WKApplicationDelegateAdaptorexample
@main
struct MyApp: App {
@WKApplicationDelegateAdaptor private var applicationDelegate: MyApplicationDelegate
var body: some Scene { ... }
}For watchOS apps using Storyboards, you must call APLApplicationDidFinishLaunching() in the WKExtensionDelegate's applicationDidFinishLaunching method.
Swift
WKExtensionDelegateexample
import AppfigurateLibrary
...
func applicationDidFinishLaunching {
APLApplicationDidFinishLaunching()
}You must call APLApplicationDidFinishLaunching() in the WKExtensionDelegate's applicationDidFinishLaunching method.
Objective-C
WKExtensionDelegateexample
@import AppfigurateLibrary;
...
- (void) applicationDidFinishLaunching {
APLApplicationDidFinishLaunching();
}WCSessionDelegate
If your watch app has an existing WCSessionDelegate, then you must add a call to the APLSessionDidReceiveMessage() method. If your watch app does not have a WCSessionDelegate then a default implementation is automatically provided.
Swift
WCSessionDelegateexample
import AppfigurateLibrary
...
func session(_ session: WCSession, didReceiveMessage message: [String : Any], replyHandler: @escaping ([String : Any]) -> Void) {
let reply = APLSessionDidReceiveMessage(message)
if reply != nil {
replyHandler(reply)
} else {
...Objective-C
WCSessionDelegateexample
@import AppfigurateLibrary;
...
- (void) session: (WCSession*) session didReceiveMessage: (NSDictionary<NSString*,id>*) message replyHandler: (void (^)(NSDictionary<NSString*,id>*)) replyHandler {
NSDictionary* reply = APLSessionDidReceiveMessage(message);
if (reply != nil) {
replyHandler(reply);
} else {
...
Test your watchOS app
To test that you've successfully updated your watchOS app to use Appfigurate:
Compile and run your watchOS app to the paired Simulator instance.
Launch the Appfigurate Simulator app.
Tap your watchOS applications row. The companion iOS app will be run and made visible. The companion iOS app will read the watchOS apps configuration, then swap back to Appfigurate.
Appfigurate's Configure app screen will now be displayed. You can now change the
debugLoggingandserverURLproperties. TapApply⌄to apply the configuration to your watchOS app.
Now jump to Supported property types.
Last updated