Instance Method

registerForRemoteNotifications

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

Declaration

- (void)registerForRemoteNotifications;

Discussion

Before calling this method, you must enable your WatchKit extension’s Push Notification capability, as described in Enable push notifications.

Call this method to register a device with APNs. If registration succeeds, the system calls your extension delegate’s didRegisterForRemoteNotificationsWithDeviceToken: method and passes it a device token. Pass this token to the provider server you use to generate remote notifications for this device. If registration fails, the system calls your extension delegate’s didFailToRegisterForRemoteNotificationsWithError: method instead.

To display alerts, play sounds, or perform other user-facing actions, you must also request authorization using the UNUserNotificationCenter class’s requestAuthorizationWithOptions:completionHandler: method. If you do not request and receive authorization for your app’s interactions, the system delivers all remote notifications to your app silently.

If your watchOS app has an iOS companion, always send notifications to both watchOS and the paired iOS device. As long as the payloads are identical, the system recognizes the duplicates, and only displays one notification to the user.

For more information on setting up remote notifications, see Setting Up a Remote Notification Server and Registering Your App with APNs.

See Also

Registering for Remote Notifications

- 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.