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

标签 cocoa appstore-sandbox

我有一个沙盒应用程序。我需要它在每次启动时启动一个辅助应用程序(从主应用程序的 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/

相关文章:

ios - 初始化 Controller 的自类

objective-c - 向 NSImageView 添加阴影

macos - 苹果电脑 : Saving information to file without modifying date stamp

macos - 防止 OS X 应用程序的沙箱容器中的原始文件通过拖放或共享扩展进行修改?

ios - 我可以在沙盒 macOS 应用程序中使用 Peertalk 或 usbmuxd 吗?

objective-c - 权限被拒绝,由 NSURL 资源泄漏引起?

iOS/OSX 应用程序组 ID,以 "group."或 "team-id."开头?

objective-c - 如何检查我的应用程序是否以全屏模式运行?

swift - 使用 Swift 和 Cocoa 处理 OS X 中的关键事件

iOS GameCenter 排行榜仅显示我在沙盒模式下的分数