Search code examples
swiftpush-notificationapple-push-notificationsapple-watchwatchos

Independent Watchkitapp APNS push notification successful send but notification does not receive in Apple Watch


I have created an independent watchkitapp in XCode, installed in apple watch and successfully sent push notification without errors from Pusher app (also in node-apn) but the notification does not arrive in app. (Tried another app for iOS and remote push notification successfully received in iOS app)

These are the steps i took

  1. In my watchkitapp I did WKExtension.shared().registerForRemoteNotifications() and took the device token

  2. UNUserNotificationCenter.current().requestAuthorization and allowed push notification on apple watch. ofcourse I set UNUserNotificationCenter.current().delegate to the InterfaceController (I tried Local Notification and local notifications display normally on the watch)

  3. On XCode watchkitapp.watchkitextension I added Push Notification on capabilities

  4. In Apple Developer page I created app id mirroring the watchkitapp bundle (not the watchkitextension one). In my case apple automatically created App Id in the server but I removed and recreated it to make sure

  5. Checked the Apple Push Notification service and generated Development SSL Cert

  6. Downloaded the Development SSL Cert and installed in keychain

  7. Opened the Pusher app and selected the installed Development SSL Cert from the list. Ran the apple watch app and obtained the Token Id... sent the payload and it says the payload is sent

  8. Tried to restart mac, iphone, apple watch, unpairing apple watch, reinstalling app but the result is the same... push is sent but does not receive in apple watch

anybody can help me how can I fix this?

enter image description here enter image description here enter image description here enter image description here


Solution

  • Finally, I got this successfully. I use node-apn to send from server.
    Here are the worth noticing things:

    1. create app id of the watchkitapp bundle in Apple Developer page

    2. install the latest version of: node-apn,

      "dependencies": { "apn": "git+https://github.com/node-apn/node-apn.git#3.0.0", [...] }

    3. should set apns-push-type

    notification.pushType (Required when delivering notifications to devices running iOS 13 and later, or watchOS 6 and later. Ignored on earlier system versions.)

    The type of the notification. The value of this header is alert or background. Specify alert when the delivery of your notification displays an alert, plays a sound, or badges your app's icon. Specify background for silent notifications that do not interact with the user.

    The value of this header must accurately reflect the contents of your notification's payload. If there is a mismatch, or if the header is missing on required systems, APNs may delay the delivery of the notification or drop it altogether.