是否可以在关闭时让 iOS 应用程序处理 WatchKit 连接请求?

Is it possible to make an iOS app process WatchKit connectivity requests while closed?

我一直在通读有关 WatchKit 连接框架的文档,试图弄清楚我是否可以将所有密集处理需求委托给我的父 iOS 应用程序。用于执行所需处理的所有代码都已存在于父应用程序中,这样做似乎比 Apple Watch 应用程序复制代码并自行尝试更有效。

我的问题是,如果 iOS 设备上的应用程序在手表套件应用程序发出请求时未处于活动状态,这是否可行?它只是将请求排队直到下次打开它还是可以将其配置为立即处理它?我希望手表始终获得某种形式的响应或请求超时。

更新:

我发现我的特定问题与在执行单独的请求后从后台线程调用回复处理程序有关。当我这样做时,我没有收到从 iOS 设备返回到 Apple Watch 的响应。这最初让我认为 iOS 设备在激活之前忽略请求。

我的解决方案是执行以下操作,以便回复处理程序始终 从主线程调用。这似乎是我在文档中一定遗漏了的沟通的关键部分(或者可能遗漏了 :o)。长话短说,在进行如下所示的更新后,我每次都成功收到回复。

dispatch_async(dispatch_get_main_queue(), { () -> Void in
    replyHandler(myResponse) // Always call from main thread!
})

WCSession 的 sendMessage APIs enable the WatchKit extension to wake the iOS app up in the background as long as reachable is true. Here is a nice step-by-step tutorial 关于使用 sendMessage。