【发布时间】:2013-06-10 19:19:32
【问题描述】:
我正在使用 Final Cut Pro X 的插件,需要将数据发送到另一个程序。到目前为止,我可以通过使用NSDistributedNotificationCenter 来做到这一点,但这是不应该工作。根据其 Apple 开发者页面:
重要提示:沙盒应用只有在不包含字典的情况下才能发送通知。如果发送应用在 App Sandbox 中,notificationInfo 必须为 nil。
Final Cut Pro X 在 Mac App Store 中出售,我所看到的一切都表明它被沙盒化了。有谁知道 FCPX 的沙箱、分布式通知中心是否存在错误,或者 FxPlug 是否在沙箱之外运行?我宁愿不让关键代码依赖于有效但不应该依赖的东西。
我在 FxPlug 中的通知发送代码:
NSDistributedNotificationCenter* dist = [NSDistributedNotificationCenter defaultCenter];
NSDictionary* dict = [NSDictionary dictionaryWithObjectsAndKeys:@"First value", @"key1",
@"Second value from FCPX", @"key2", @"Third & final value", @"3key3", nil];
[dist postNotificationName:@"FCPX plugin"
object:@"SFPCommApp"
userInfo:dict];
并在其他应用中接收代码:
m_center = [NSDistributedNotificationCenter defaultCenter];
[m_center addObserver:self
selector:@selector(GetNotification:)
name:nil
object:listenTo];
// in GetNotification
NSString *notifString = [notification description];
NSString *dispString = @"Got notification from Final Cut Pro X";
dispString = [dispString stringByAppendingString:notifString];
// dispString displayed in a dialog
它可以在 Xcode 调试器中运行,并且完全在 Xcode 之外(都从 Finder 启动)。另外,我需要支持10.6,所以不能使用XPC。
关于从 FxPlug 发送数据的其他方法的想法?谢谢!
【问题讨论】: