我如何在启用沙箱的辅助应用程序中终止我的应用程序



我已经创建了一个辅助应用程序,该应用程序可监视iTunes并启动/终止主应用程序。

发射效果很好。唯一的问题是,由于沙箱,我不允许终止主应用程序。我得到了这3个日志:

12/23/12 8:45:37.522 PM appleeventsd[70]: Sandboxed application with pid 8293 attempted to lookup App:"Significator 2"/8877/0x0:0x150150 ???? sess=100011 but was denied due to sandboxing. (handleMessage()/appleEventsD.cp #2007) com.apple.coreservices.appleevents.peer.0x7fd9c2401f00.xpcq

12/23/12 8:45:37.000 PM kernel[0]: Sandbox: sandboxd(8888) deny mach-lookup com.apple.coresymbolicationd

12/23/12 8:45:37.873 PM sandboxd[8888]: ([8293]) SignificatorHelp(8293) deny appleevent-send ch.ilijatovilo.significator-2

我尝试在辅助应用程序中终止它:

NSRunningApplication *app = [[NSRunningApplication runningApplicationsWithBundleIdentifier:[self mainApplicationBundle].bundleIdentifier] objectAtIndex:0];
[app terminate];

当然,我可以在主应用中添加另一个观察者,但我想避免。

得到它,我必须添加一个临时权利例外:

<key>com.apple.security.temporary-exception.apple-events</key>
<array>
    <string>mainAppBundleIdentifier</string>
</array>

如果将应用程序放在应用程序组中,则可以将信号发送到主应用程序以终止自身。

推荐到10.8 IPC的推荐方法是使用nsxpcconnection。

使用nsxpcconnection在沙箱中查看代码

最新更新