WCSession 无法在配对的手表和手机模拟器上激活

mos*_*ene 5 xcode objective-c ios watchos watchconnectivity

概述:

  • 我正在构建一个非常简单的 Apple Watch 和 iPhone 应用程序
  • 我正在使用 Xcode 中的手表和手机模拟器运行/调试应用程序
  • 我正在使用 WatchConnectivity 使他们进行通信
  • WCSession尽管它们已配对,但我无法在手表或手机模拟器上激活

在 Xcode Devices 窗口中,我的手表模拟器和手机模拟器是配对的。我可以使用 WatchKit App 方案启动我的手表应用程序(它也启动手机模拟器,但不打开移动应用程序)。然后我通过单击手机模拟器上的应用程序图标来启动我的移动应用程序。

移动应用:

  • ViewController 工具 WCSessionDelegate
  • WatchConnectivity 会话在viewDidLoad方法中被激活

观看应用:

  • InterfaceController 工具 WCSessionDelegate
  • WatchConnectivity 会话在willActivate方法中被激活

当我运行 WatchKit 应用程序时,会记录以下消息:

[WC] WCSession has not been activated
Run Code Online (Sandbox Code Playgroud)

当我通过单击应用程序图标打开移动应用程序时,我收到以下消息:

[WC] WCSession has not been activated
Apple Watch is not paired
[WC] WCSession has not been activated
WatchKit app is not installed on the paired watch
Run Code Online (Sandbox Code Playgroud)

(我添加了日志语句来显示检查结果isPairedisWatchAppInstalled移动应用程序中的会话)

我的WCSession激活代码是在我的手机应用程序,并观看应用中的相同:

if ([WCSession isSupported]) {
  WCSession *session = [WCSession defaultSession];
  session.delegate = self;
  [session activateSession];
  // print debugging statements about paired watch, etc.
}
Run Code Online (Sandbox Code Playgroud)

有谁知道为什么 WatchConnectivity 没有检测到手机和手表模拟器配对的事实?为什么不WCSession激活?