Class

WKExtension

An object that manages behaviors shared by an app’s interface controllers.

Declaration

class WKExtension : NSObject

Overview

Every WatchKit extension has a single extension object that the system creates and manages. You use the extension object 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

class func shared() -> WKExtension

Returns the shared WatchKit extension object.

Accessing the Extension Delegate

var delegate: WKExtensionDelegate?

The delegate of the WatchKit extension object.

protocol WKExtensionDelegate

A collection of methods that manage the app-level behavior of a WatchKit extension.

Opening a URL Resource

func openSystemURL(URL)

Opens the specified system URL.

Getting the Interface Controllers

var rootInterfaceController: WKInterfaceController?

The app’s root interface controller.

var visibleInterfaceController: WKInterfaceController?

Returns the last visible interface controller.

Managing the Execution State

var applicationState: WKApplicationState

The runtime state of the Watch app.

enum WKApplicationState

The running states of your Watch app.

var isApplicationRunningInDock: Bool

A Boolean value that indicates whether the app is running in the dock.

var isFrontmostTimeoutExtended: Bool

A Boolean value that determines whether the app extends its time as the frontmost app.

Managing the User Interface

var isAutorotating: Bool

A Boolean value that determines whether the interface automatically rotates when the user flips their wrist.

var isAutorotated: Bool

A Boolean value that indicates whether the user interface is currently rotated so that it is properly oriented for another viewer.

func enableWaterLock()

Disables the Apple Watch touch screen to prevent accidental taps while the watch is submerged.

Relationships

Inherits From

Conforms To

See Also

Extension Architecture

Working with the watchOS App Lifecycle

Learn how the watchOS app lifecycle operates and respond effectively to lifecycle notification methods.

protocol WKExtensionDelegate

A collection of methods that manage the app-level behavior of a WatchKit extension.

class WKInterfaceDevice

An object that provides information about the user’s Apple Watch.