不同app之间可以使用NSNotificationCenter进行通信吗?
应用程序可以在内部使用 NSNotificationCenter
来让不同部分相互通信,但这是否可以扩展,以便不同的应用程序可以使用它来通信?
编辑:对于 iOS 与 OSX 之间的混淆,我们深表歉意。我只添加了 iOS 标签,我不知道如何/谁/为什么还添加了 Objective-C 标签,这不是我。
An app can make internal use of NSNotificationCenter
for different parts to communicate with each other, but can this be extended such that differing apps can use it to communicate?
Edit: sorry for the confusion about iOS versus OSX. I only added the iOS tag, I don't know how/who/why an objective-c tag also got added, it wasn't me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
抱歉,我的回答很简短,但在这种情况下,这就是全部 - 不,他们不能。
您可以注册来处理 URL 类型,然后以这种方式启动传递一些数据。
Sorry for a brief answer but in this case that's all there is to it - no they cannot.
You can register to handle a URL type and then launch pass some data that way.
Nick 的答案当然是正确的,但如果您正在寻找
NSNotificationCenter
的替代方案,那么在进程之间工作,您可以尝试使用 CoreFoundation.framework 中的 Darwin 通知机制。如果您使用 Darwin 通知中心,则这适用于进程之间。查看 Stack Overflow 上的示例
...以及另一个带有示例回调的示例
请注意,我尚未在 iTunes App Store 上的任何应用程序中使用过此功能。 这些 API 不是私有的 ,但是 Apple 当然可以拒绝使用他们喜欢的任何内容,即使它不是私有 API。我只是提供此解决方案作为一种可能性,无法预测 App Store 的可接受性,甚至无法知道您(或阅读此页面的其他人)是否需要将他们的应用程序提交到 App Store。
我还将链接到这个类似的问题(当前未解决)
Nick's answer is certainly correct, but if you're looking for an alternative to
NSNotificationCenter
, that works between processes, you can try using the Darwin notification mechanism in CoreFoundation.framework. This works between processes, if you use the Darwin notification center.See example here on Stack Overflow
... and another one with an example callback
Note that I have not used this in any apps on the iTunes App Store. These APIs are not private, however Apple certainly can reject usage of whatever they like, even if it's not a private API. I just offer this solution as a possibility, without being able to predict App Store acceptibility, or even knowing whether you (or others reading this page) need to submit their apps to the App Store.
I'll also link to this similar question (currently unsolved)
我认为你需要一个服务器来处理两个应用程序之间的通信。
假设您希望应用程序 A 和应用程序 B 相互通信。让两个应用程序定期向服务器 S 报告它们的“位置”。此外,两个应用程序都应该监听 S。
不确定在后台运行的应用程序如何有效地监听来自服务器的数据。
了解 iOS 即时通讯应用程序的工作原理可能会有所帮助。也许有一些开源项目可以帮助解决这个问题(并且可以适应您的需求)。
I think you need a server to handle the communication between two apps.
Say you want app A and app B to communicate with each other. Have both apps periodically report their "locations" to a server S. Also both apps should be listening to S.
Not sure how effectively apps running in the background can listen for data from a server.
Might be helpful to look into how iOS instant messaging apps work. Perhaps there's some open source projects that help with this (and can be adapted to your needs).