共享 Cocoa FBA 实例(无脸后台应用程序或简称代理)
目标
我正在构建一个 FBA(不露面后台应用程序)。其他应用程序(客户端)使用 NSDistributedNotificationCenter 向 FBA 注册。当客户端注册时,我希望能够直接在客户端对象上调用消息。
第一个问题:
当客户端发布请求注册的通知时,我本来想给客户端设置一个userInfo key。
[NSValue valueWithPointer:self]; // 其中 self 是客户端应用程序
但是,当发布通知时,会生成错误,指出 userInfo 不可序列化。
问题 2: 我通过给 userInfo 一个 NSNumber 来解决这个问题。
[NS编号 numberWithUnsignedInteger:(NSUInteger)self];
现在,FBA 在收到通知时会收到适当的指针。但是,当我尝试访问对象(客户端)时,会生成 EXEC_BAD_ACCESS 错误。
所以,我想我的问题是,如何访问另一个内存空间?我是否必须以某种方式创建共享内存空间?这可能吗?我的这种设计模式是否走错了方向?
谢谢。
Objective
I'm building an FBA (Faceless Background Application). Other applications (clients) register with the FBA using the NSDistributedNotificationCenter. When a client registers, i'd like to be able to invoke messages directly on the client object.
First Issue:
When the client posts a notification requesting registration, I originally wanted to set a userInfo key to the client.
[NSValue valueWithPointer:self]; //
where self is the client application
However when the notification is posted, an error is generated saying the userInfo is not serializable.
Issue 2:
I created a work around by giving the userInfo a NSNumber instead.
[NSNumber
numberWithUnsignedInteger:(NSUInteger)self];
The FBA now receives the appropriate pointer when it receives the notification. However when I try to access the object(the client), a EXEC_BAD_ACCESS error is generated.
So, I guess my question is, how can I get access to another memory space? Do I have to create a shared memory space somehow? Is this possible? Am I stepping in the wrong direction with this design pattern?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果适合您的话,来回发送通知绝对是最简单的解决方案。
但是,如果您需要更多 Cocoa 通过 NSProxy 等支持分布式对象。请参阅 http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/DistrObjects/DistrObjects.html#//apple_ref/doc/uid/10000102-SW1
Sending notifications back and forth is definitely the simplest solution, if that works for you.
However, if you need more Cocoa supports distributed objects via
NSProxy
et al. See http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/DistrObjects/DistrObjects.html#//apple_ref/doc/uid/10000102-SW1