2012-04-29 94 views
4

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

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.

但是,我不能使用这个API,而不要求用户第一,因为应用商店审查指南2.26:

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

因此,使用此解决方法意味着询问用户“每次登录时启动助手都可以?如果不是,则不能使用此应用程序!”显然,这不是理想......

+0

不确定这是否与rdar:// 10934199相关,因为launchApplicationAtURL在沙箱下失败,即使它尝试的应用程序启动已由用户手动启动 – valexa 2012-05-08 19:34:07

+0

您是否可以获得安装用户启动代理的权限,该代理将检查您的应用是否正在运行并启动帮助程序? – Colin 2012-07-18 19:01:55

回答

2

一个可行的解决方法是使用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.

。所以必须有更好的解决方案...

+0

在控制台“xcrun:error:can not be used within a App Sandbox”中使用/ usr/bin/opendiff会产生以下错误。即使苹果的指导方针声明“系统自动允许沙盒应用程序”“读取世界可读的文件,在某些目录中,包括以下目录:”“/ usr/bin”...我想这不是真的了吗? – 2015-04-11 14:37:31

0

你可以使用SMLoginItemSetEnabled。你必须要求用户同意一次。毕竟,使用SMLoginItemSetEnabled首次启动的帮助程序应用程序会在用户每次登录时自动启动。

+0

不适合我。我有一个应用程序,只是在菜单栏中,并没有窗口或码头的存在。 'SMLoginItemSetEnabled'将注册助手,但助手无法启动主应用程序。该应用程序是沙盒的应用程序商店。 – SpaceDog 2017-07-23 11:04:02