0

如果我的手表在后台并且 iPhone 应用程序在前台,我想将数据从 iWatch 发送到 iPhone。我通过计时器方法传输数据。它每一秒都在呼唤。WCSessionDelegate方法实现了文件 iPhone 应用程序文件和手表套件扩展文件。WCSessionDelegate方法didReceiveUserInfo,,didReceiveMessagereplyHandlerdidReceiveMessage实现。

let applicationData = ["class":"progress", "mode":"steps"]
WCSession.default.transferUserInfo(applicationData as [String : AnyObject])
4

1 回答 1

2

经过一些试验和使用代码后,我解决了这个问题,早些时候我在 ViewController 的 viewDidLoad 方法中配置和激活了 WCSession,我发现 Apple 不推荐这种方法,他们的建议是我们应该始终在很早的时候设置 WCSession应用程序的生命周期(iWatch 和 iPhone)结束。如果我们在 AppDelegate 和 ExtensionDelegate 中激活它,这将顺利进行。

供参考,您可以查看https://developer.apple.com/videos/play/wwdc2015/713/

于 2018-02-28T05:58:42.783 回答