cocoa – 从沙盒应用程序启动帮助程序

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

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

错误是:

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

现在,该错误具有误导性,因为如果我禁用沙盒权利,应用程序就会启动.显然这是一个错误,正如here报道的那样.

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

我可以使用SMLoginItemSetEnabled,如here所述:

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 Review Guideline 2.26,我无法在不首先询问用户的情况下使用此API:

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

因此,使用此解决方法意味着询问用户“每次登录时是否可以启动帮助程序?如果没有,则无法使用此应用程序!”显然,这并不理想……

解决方法

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

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

这可以从沙箱中运行良好,并且似乎与Mac App Store查看指南兼容.

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

The application cannot be opened because its executable is missing.

当我关闭沙盒时不会发生此错误.所以必须有一个更好的解决方案……

相关文章

我正在用TitaniumDeveloper编写一个应用程序,它允许我使用Ja...
我的问题是当我尝试从UIWebView中调用我的AngularJS应用程序...
我想获取在我的Mac上运行的所有前台应用程序的应用程序图标....
我是一名PHP开发人员,我使用MVC模式和面向对象的代码.我真的...
OSX中的SetTimer在Windows中是否有任何等效功能?我正在使用...
我不确定引擎盖下到底发生了什么,但这是我的设置,示例代码和...