How can I terminate my app in a helper app with sandboxing enabled?

人盡茶涼 提交于 2019-11-28 01:39:46

问题


I've created a helper app, which monitors iTunes and launches/terminates the main app.

The launching works perfectly. The only problem is that I'm not allowed to terminate the main app, because of sandboxing. I get those 3 logs:

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

I've tried terminating it like this in the helper app:

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

Of course, I could add another observer in the main app, but I want to avoid that.


回答1:


Got it, I had to add a temporary entitlement exception:

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



回答2:


If you place your apps in an Application Group you can send a signal to the main app to terminate itself.




回答3:


The recommended way to IPC in 10.8 is using NSXPCConnection.

See the code at Sandboxing with NSXPCConnection



来源:https://stackoverflow.com/questions/14014192/how-can-i-terminate-my-app-in-a-helper-app-with-sandboxing-enabled

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!