Class

WKExtension

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

Declaration

@interface 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

+ sharedExtension

Returns the shared WatchKit extension object.

Accessing the Extension Delegate

delegate

The delegate of the WatchKit extension object.

WKExtensionDelegate

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

Opening a URL Resource

- openSystemURL:

Opens the specified system URL.

Getting the Interface Controllers

rootInterfaceController

The app’s root interface controller.

visibleInterfaceController

Returns the last visible interface controller.

Managing the Execution State

applicationState

The runtime state of the Watch app.

WKApplicationState

The running states of your Watch app.

isApplicationRunningInDock

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

frontmostTimeoutExtended

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

- scheduleBackgroundRefreshWithPreferredDate:userInfo:scheduledCompletion:

Schedules a background task to refresh your app’s data.

Managing the User Interface

autorotating

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

autorotated

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

- enableWaterLock

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

Deprecated

Managing the Snapshot

- scheduleSnapshotRefreshWithPreferredDate:userInfo:scheduledCompletion:

Schedules a background task to refresh your app’s snapshot.

Registering for Remote Notifications

- registerForRemoteNotifications

Register to receive remote notifications from the Apple Push Notification service (APNs).

- unregisterForRemoteNotifications

Unregister for all remote notifications received from Apple Push Notification service (APNs).

registeredForRemoteNotifications

A Boolean value that indicates if the app has successfully registered for remote notifications.

Relationships

Inherits From

See Also

App Infrastructure

Working with the watchOS App Life Cycle

Learn how the watchOS app life cycle operates and respond to life cycle notification methods.

Keeping Your watchOS Content Up to Date

Ensure that your watchOS content is relevant and up to date.

Authenticating Users on Apple Watch

Create an account sign-up and sign-in strategy for Apple Watch.

WKExtensionDelegate

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

WKInterfaceDevice

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