WatchOS2 WCSession WatchKitExtension 中 WCSession 可以有多少个委托? [英] WatchOS2 WCSession How many delegates can the WCSession have in WatchKitExtension?

查看:25
本文介绍了WatchOS2 WCSession WatchKitExtension 中 WCSession 可以有多少个委托?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 iOS 应用通过 WatchConnectivity 框架及时发送信息.接收端实现WCSession的委托.

My iOS app sends timely information via the WatchConnectivity framework. The receiving side implements the delegate of WCSession.

我有 2 个 interfaceController 需要从 WCSession 发送的信息.

I have 2 interfaceControllers that need the information sent from the WCSession.

一个是glanceInterfaceController,另一个是我的mainInterfaceController.

One is the glanceInterfaceController and the other is my mainInterfaceController.

是否可以同时为它们分配委托并同时接收从我的 iOS 应用程序发送的 userInfo 或 applicationContext?还是只能分配一个 WCSession 委托,而我的控制器需要从分配的对象中获取数据?

Can both of them be assigned the delegate and both receive the userInfo or applicationContext sent from my iOS app at the same time? or can there only be one WCSession delegate assigned and my controllers need to get the data from the object that is assigned?

谢谢!

推荐答案

WCSession 一次仅支持一个委托.如果您希望在有新传入内容时通知代码的多个部分,您必须创建一个包装类,该类具有与 WCSessionDelegate 类似的回调但支持多个观察者,或者您可以使用本地通知来转发内容.也许更好;让您的 WCSessionDelegate 更新应用的数据存储,然后通知从数据存储读取的代码部分已更新,以便他们刷新视图?

WCSession only supports a single delegate at a time. If you want multiple parts of your code to be notified when there is new incoming content you'd have to either create a wrapper class that has similar callbacks to the WCSessionDelegate but supports multiple observers or you could use local notifications to forward the contents on. Perhaps better; have your WCSessionDelegate update the app's data store and then notify the parts of your code reading from the data store that it has been updated so they'll refresh their views?

这篇关于WatchOS2 WCSession WatchKitExtension 中 WCSession 可以有多少个委托?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆