从沙盒应用程序启动助手 [英] Launch helper from sandboxed application

查看:153
本文介绍了从沙盒应用程序启动助手的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个沙盒应用程序。我需要它在每次启动时(从主应用程序包中)启动一个助手应用程序。但是,这将失败:

I have a sandboxed application. I need it to launch a helper application (from within the main application's bundle) every time it starts up. However, this fails:

NSError *error;
[[NSWorkspace sharedWorkspace] launchApplicationAtURL:helperURL
                               options:NSWorkspaceLaunchDefault
                               configuration:nil
                               error:&error];

错误是:


由于损坏的应用程序 Helper无法启动,NSUnderlyingError = 0x10214c700操作无法完成。(OSStatus错误-10827。)}

The application "Helper" could not be launched because it is corrupt., NSUnderlyingError=0x10214c700 "The operation couldn’t be completed. (OSStatus error -10827.)"}

现在,该错误具有误导性,因为如果我禁用沙箱授权,应用程序可以正常启动。显然这是一个错误,如此处所报道。

Now, the error is misleading, because the app launches fine if I disable the sandbox entitlement. Apparently this is a bug, as reported here.

我的问题是:有解决方法吗?

我可以使用 SMLoginItemSetEnabled ,如此处所述:

I could use SMLoginItemSetEnabled, as described here:


通过 true 立即启动助手应用程序,并指示每次启动该助手应用程序用户登录的时间。传递 false 终止帮助程序,并指示用户登录后不再启动它。

Pass true to start the helper application immediately and indicate that it should be started every time the user logs in. Pass false to terminate the helper application and indicate that it should no longer be launched when the user logs in.

但是,由于App Store审核指南2.26,我不能不先询问用户就使用此API:

But, I can't use this API without asking the user first, because of App Store Review Guideline 2.26:

设置为自动启动或在启动时自动运行其他代码或使用以下命令登录的应用ut用户同意将被拒绝

Apps that are set to auto-launch or to have other code automatically run at startup or login without user consent will be rejected

因此,使用此替代方法将要求用户每次您启动助手都可以吗?登录?否则,您将无法使用该应用程序!显然,这并不理想...

So, using this workaround would mean asking the user "Is it OK to launch a helper every time you log in? If not, you can't use this app!" Clearly, that's not ideal...

推荐答案

一个可行的解决方法是使用 NSTask 生成 / usr / bin / open 并为其指定助手应用程序的路径:

A viable workaround is to use NSTask to spawn /usr/bin/open and give it the helper app's path:

NSTask *task = [NSTask new];
[task setLaunchPath: @"/usr/bin/open"];
[task setArguments: [NSArray arrayWithObjects: helperPath, nil]];
[task launch];

这在沙盒中运行良好,并且似乎与Mac App Store审查指南兼容。

This runs fine from the sandbox, and appears to be compatible with the Mac App Store Review Guidelines.

更新:在进一步检查后,该技术经常因错误而失败

Update: On further examination, this technique frequently fails with the error


由于缺少可执行文件而无法打开该应用程序。

The application cannot be opened because its executable is missing.

关闭沙箱功能后不会发生此错误,因此必须有更好的解决方案...

This error does not occur when I've turned off sandboxing. So there must be a better solution...

这篇关于从沙盒应用程序启动助手的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆