WatchOS2 WCSession WCSession可以在WatchKitExtension中拥有多少个代理? [英] WatchOS2 WCSession How many delegates can the WCSession have in WatchKitExtension?

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

问题描述

我的iOS应用程序通过WatchConnectivity框架及时发送信息。接收方实现WCSession的委托。

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

我有2个需要从WCSession发送的信息的interfaceControllers。

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 WCSession可以在WatchKitExtension中拥有多少个代理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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