直接向 watchOS 2 发送推送通知?

Sending push notifications directly to watchOS 2?

在 iOS,我们可以在 UIApplication 上使用 registerForRemoteNotifications 方法注册推送通知。

我想创建一个 watchOS 2 应用程序,即使我的手表没有连接到 phone(但连接到 Wi-Fi)也能正常工作。我想直接从服务器向手表发送推送通知。有办法吗?

如果是这样,watchOS 2 扩展中这些方法的等价物是什么?

  application.registerForRemoteNotifications
  application(:, didRegisterForRemoteNotificationsWithDeviceToken:)
  application(:, didFailToRegisterForRemoteNotificationsWithError:)
  application(:, didReceiveRemoteNotification:)

如果没有,我的其他选择是什么?

目前无法直接从手表服务器获取通知。如Notification Essentials for watch

所述

Apple Watch displays local and remote notifications only if the containing iOS supports them. For information about how to support local and remote notifications in your iOS app, see Local and Remote Notification Programming Guide.

这也提到

When one of your app’s local or remote notifications arrives on the user’s iPhone, iOS decides whether to display that notification on the iPhone or on the Apple Watch

现在有一些情况,如果您的 phone 处于活动状态并且 notification 到达,它将在 phone 收到。但是如果 phone 被锁定并且手表处于活动状态然后 notification 到达它将显示在 watch.

Apple Push Notification Service Doc中也提到

Apple Push Notification service (APNs) is the centerpiece of the remote notifications feature. It is a robust and highly efficient service for propagating information to iOS (and, indirectly, watchOS), tvOS, and OS X devices.