Protocol

WKExtensionDelegate

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

Declaration

protocol WKExtensionDelegate

Overview

Implement the delegate’s methods to respond to your app’s life-cycle events, such as the activation and deactivation of your app. You can also implement delegate methods to respond to background tasks, Siri intents, workout sessions, or Handoff activity from another devices.

WatchKit creates your delegate object automatically by instantiating the class assigned to the WKExtensionDelegateClassName key in your WatchKit extension’s Info.plist file. By default, this class is named ExtensionDelegate. The system then assigns the delegate object to the delegate property of the shared WKExtension object.

Topics

Monitoring State Changes

Working with the watchOS App Life Cycle

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

func applicationDidFinishLaunching()

Tells the delegate that the launch process is almost done and the extension is almost ready to run.

func applicationDidBecomeActive()

Tells the delegate that the Watch app is now visible and processing events.

func applicationWillResignActive()

Tells the delegate that the Watch app is about to be deactivated.

func applicationWillEnterForeground()

Tells the delegate that the app is about to transition from the background to the foreground.

func applicationDidEnterBackground()

Tells the delegate that the app has transitioned from the foreground to the background.

func deviceOrientationDidChange()

Tells the delegate that the device's orientation has changed.

func handle(Set<WKRefreshBackgroundTask>)

Tells the delegate that the app has received one or more background tasks.

Responding to Intents

Setup Now Playing Interface

func handleRemoteNowPlayingActivity()

Tells the delegate when the user plays audio in the corresponding iOS app.

Handling a Workout Session

func handle(HKWorkoutConfiguration)

Tells the delegate that the user started a workout session on the paired iPhone.

func handleActiveWorkoutRecovery()

Tells the delegate when the app relaunches after crashing during an active workout session.

Handling Extended Runtime Sessions

func handle(WKExtendedRuntimeSession)

Tells the delegate that the system launched your app to resume an extended runtime session.

Managing Remote Notifications

func didRegisterForRemoteNotifications(withDeviceToken: Data)

Tells the delegate that the app successfully registered with Apple Push Notification service (APNs).

func didFailToRegisterForRemoteNotificationsWithError(Error)

Tells the delegate that Apple Push Notification service (APNs) cannot successfully complete the registration process.

enum WKBackgroundFetchResult

The result of an attempt to download the content associated with a remote notification.

Coordinating Handoff Activity

func handleUserActivity([AnyHashable : Any]?)

Responds to Handoff–related activity from complications and notifications.

func handle(NSUserActivity)

Responds to Handoff–related activity from Siri.

Deprecated Methods

func didReceiveRemoteNotification([AnyHashable : Any])

Tells the delegate that a remote notification arrived.

Deprecated
func didReceive(UILocalNotification)

Tells the delegate that a local notification was triggered.

Deprecated
func handleAction(withIdentifier: String?, forRemoteNotification: [AnyHashable : Any])

Delivers a remote notification payload and a user-selected action to the app.

Deprecated
func handleAction(withIdentifier: String?, forRemoteNotification: [AnyHashable : Any], withResponseInfo: [AnyHashable : Any])

Delivers a remote notification payload and user response information to the app.

Deprecated
func handleAction(withIdentifier: String?, for: UILocalNotification)

Delivers a local notification payload and a user-selected action to the app.

Deprecated
func handleAction(withIdentifier: String?, for: UILocalNotification, withResponseInfo: [AnyHashable : Any])

Delivers a local notification payload and user response information to the app.

Deprecated

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.

class WKExtension

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

class WKInterfaceDevice

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