gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 16:15:06 27 4
gpt4 key购买 nike

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

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 审核指南 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.

当我关闭沙箱时,不会发生此错误。所以必须有更好的解决方案......

关于cocoa - 从沙盒应用程序启动帮助程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10368972/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com