WKExtension
The centralized point of control and coordination for extension-based apps running in watchOS.
Declaration
@MainActor class WKExtensionOverview
In Xcode 13 and earlier the system divides a watchOS app into two sections:
- WatchKit app
An app bundle that contains your app icon. For storyboard-based apps, it also includes your storyboard and any assets used by the storyboard.
- WatchKit extension
An extension that contains your watchOS app’s code.
In Xcode 14 and later, you can produce watchOS apps with a single watchOS app target for code, assets, extensions, and localizations. These single-target watchOS apps can run on watchOS 7 and later
Apps with separate WatchKit app and extensions have a single extension object. While the system creates and manages this object, you can access it to perform app-level tasks such as opening URLs and getting the root interface controller of your app.
As relevant events occur within your WatchKit app, the extension object notifies its delegate of those events. Your delegate object can implement the methods it needs to provide an appropriate response to life cycle events, handle notifications, or handle Handoff–related behaviors. For more information about the methods of the delegate, see WKExtensionDelegate.
Topics
Getting the extension object
Accessing the extension delegate
Opening a URL resource
Getting the interface controllers
Managing the execution state
applicationStateWKApplicationStateisApplicationRunningInDockscheduleBackgroundRefresh(withPreferredDate:userInfo:scheduledCompletion:)isFrontmostTimeoutExtended
Managing the user interface
Managing the snapshot
Observing messages from the notification center
applicationDidFinishLaunchingNotificationapplicationDidBecomeActiveNotificationapplicationWillResignActiveNotificationapplicationWillEnterForegroundNotificationapplicationDidEnterBackgroundNotification