Apple Watch OS 2:是否可以在 Watch 应用程序不在前台的情况下将数据从 iPhone 传输到 Watch 应用程序?

Apple Watch OS 2: Is there a to transfer data from iPhone to Watch App without Watch app being in foreground?

我有一个手表应用程序需要从 iPhone 应用程序获取数据。我是这样转的

    if ([WCSession isSupported]) {
       WCSession *session = [WCSession defaultSession];
       session.delegate = self;
       [session activateSession];
       }

     if ([[WCSession defaultSession] isReachable]) {
          NSArray *keys = [NSArray arrayWithObjects: @"data", @"data1" ,nil];
          NSArray *objects = [NSArray arrayWithObjects:data,data1, nil];
          NSDictionary *applicationDict = [NSDictionary dictionaryWithObjects:objects forKeys:keys];
         [[WCSession defaultSession] sendMessage:applicationDict replyHandler:^(NSDictionary *replyHandler) {

  } errorHandler:^(NSError *error) {

    }];
  }

然后就这样收到了。

- (void)session:(nonnull WCSession *)session didReceiveMessage:(NSDictionary<NSString *,id> *)message replyHandler:(void(^)(NSDictionary<NSString *,id> *))replyHandler {

}

但是,这仅在 Apple Watch 位于前台时有效。有没有一种方法可以让 Apple Watch 应用程序在没有应用程序在前台的情况下接收数据,或者可能有另一种方法可以做到这一点,比如在发送数据之前唤醒 Apple Watch 应用程序。

您可以做的是使用 WCSession 对象上的 updateApplicationContext:error: 方法将更新的数据发送到您的手表。当您的手表应用程序唤醒时,它将收到包含更新数据的上下文对象。