简体   繁体   English

如何访问不同目标的类实例?

[英]How to access different target's class instance?

I'm using Notification ContentExtension which is in the different target from the main target. 我正在使用Notification ContentExtension,它位于与主要目标不同的目标中。

I want to access and call the method of AppDelegate located in the main target from the different target. 我想从另一个目标访问并调用位于主要目标中的AppDelegate的方法。

Is this possible? 这可能吗? I tried with notification-observer pattern but it doesn't seem to reach to main target's instance. 我尝试使用notification-observer pattern但似乎无法到达主要目标的实例。 It seems like they are working separately. 似乎他们正在分开工作。

NOTE: I'm NOT asking a way to share a file in different targets. 注意:我不是在要求在不同目标中共享文件的方法。

MMWormhole is a great tool to do just this. MMWormhole是执行此操作的好工具。 It's just like NotificationCenter but with the added benefit that the notifications can cross from an extensions target back to the main app's target. 就像NotificationCenter一样,但附加的好处是通知可以从扩展目标跨回到主应用程序的目标。

https://github.com/mutualmobile/MMWormhole https://github.com/mutualmobile/MMWormhole

(there are plenty of examples in the README for the project) (该项目的自述文件中有很多示例)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM