Search code examples
iosapple-push-notificationsapple-watchwatchos-6

How to configure push notifications in independent apple watch application


We are developing independent apple watch application(Watch os 6) and we need to receive push notification. So, how do we receive push notifications directly on watch?

Because of it is a independent app we don't have apple phone applications to support push notifications.


Solution

  • For independent watchOS apps you must register for remote push notifications by calling WKExtension.shared().registerForRemoteNotifications(). Generally, you make this call in the applicationDidFinishLaunching() delegate method implemented by your extension delegate. After calling to register for remote notifications, you should handle the success or failure by implementing didRegisterForRemoteNotifications(withDeviceToken:) and didFailToRegisterForRemoteNotificationsWithError(_:), respectively, in your extension delegate.

    And regarding the presentation of a push notification (according to Apple's Developer documentation):

    To display alerts, play sounds, or perform other user-facing actions, you must also request authorization using the UNUserNotificationCenter class’s requestAuthorization(options: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.