独立 Watchkitapp APNS 推送通知成功发送但在 Apple Watch 中未收到通知

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

我在 XCode 中创建了一个独立的 watchkitapp,安装在 apple watch 中并成功地从 Pusher 应用程序(也在 node-apn 中)发送推送通知而没有错误,但通知没有到达应用程序。 (为 iOS 尝试了另一个应用程序,并且在 iOS 应用程序中成功接收了远程推送通知)

这些是我采取的步骤

  1. 在我的 watchkitapp 中,我做了 WKExtension.shared().registerForRemoteNotifications() 并获取了设备令牌

  2. UNUserNotificationCenter.current().requestAuthorization 并允许在 Apple Watch 上推送通知。当然,我将 UNUserNotificationCenter.current().delegate 设置为 InterfaceController(我尝试了本地通知,本地通知在手表上正常显示)

  3. 在 XCode watchkitapp.watchkitextension 我在功能上添加了推送通知

  4. 在 Apple Developer 页面中,我创建了镜像 watchkitapp 包(不是 watchkitextension 包)的应用程序 ID。在我的例子中,苹果在服务器中自动创建了 App Id,但我删除并重新创建它以确保

  5. 检查了 Apple 推送通知服务并生成了开发 SSL 证书

  6. 已下载开发 SSL 证书并安装在钥匙串中

  7. 打开 Pusher 应用程序并从列表中选择已安装的开发 SSL 证书。 运行 apple watch 应用程序并获得了令牌 ID... 发送了有效载荷,它说有效载荷已发送

  8. 尝试重启mac,iphone,apple watch,取消配对apple watch,重装app但结果一样...推送已发送但未收到在 Apple Watch 中

谁能帮我解决这个问题?

终于,我成功了。我使用 node-apn 从服务器发送。
以下是值得注意的事情:

  1. 在 Apple 开发者页面中创建 watchkitapp 包的应用程序 ID

  2. 安装最新版本:node-apn,

    “依赖项”:{ "apn": "git+https://github.com/node-apn/node-apn.git#3.0.0", [...] }

  3. 应该设置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.