我正在使用HKHealthStore.startWatchApp从我的iPhone应用程序触发Apple Watch上的锻炼 . 根据文档,我希望最终触发我的WKExtensionDelegate的handle(_ workoutConfiguration:)方法,以便监视应用程序实际上可以调用 HKHealthStore.start(workoutSession) 开始锻炼会话 .

除以下场景外,此方法效果很好:

  • WatchKit应用程序已在 Watch 上启动并处于非活动状态(Watch的屏幕已关闭)

  • iPhone应用程序调用startWatchApp . 在很短的时间之后,使用 success == true调用完成回调

  • 如果我在此之后唤醒Apple Watch的屏幕,我的WatchKit应用程序将在前台运行,可能是由 startWatchApp 调用触发的

  • 但是,即使在我唤醒屏幕后,也永远不会调用WKExtensionDelegate的 handle(_ workoutConfiguartion:) . 所以锻炼课程从未开始

Am I doing something wrong? Is this behavior by design, and thus I need to use WatchConnectivity or some other mechanism to start a workout in this specific case?

一切都按预期工作的场景( handle 被调用,我可以开始锻炼课程):

  • 观看屏幕已开启,我的观看应用已启动 . 无论我的应用程序是否是当前位于前台的应用程序,这都有效

  • Watch应用程序根本没有运行,startWatchApp必须启动"cold" . 无论 Watch 的屏幕是否打开,这都有效