无法在沙盒 cocoa 应用程序中执行 shell 脚本命令

Can't execute shell script commands in sandboxed cocoa app

我开发了一个 cocoa 应用程序,用于构建、归档和创建 iOS 应用程序文件。现在我想将它发布到 Mac App Store。我的应用程序运行正常,但不是在沙盒模式下。 App结构如下:

MyApp.app
|_Contents
  |_Resources
    |_BuildTask.command
  1. 我做的第一件事是获得执行“BuildTask.command”的权限。

     NSTask *permissionTask = [[NSTask alloc] init];
     permissionTask.launchPath = @"/bin/bash";
     permissionTask.arguments = @[@"-c", [NSString stringWithFormat:@"chmod +x %@", pathToBuildTask], @"run"];
     [permissionTask launch];
     [permissionTask waitUntilExit];
    

否则,BuildTask 会产生错误:

Problem Running Task: launch path not accessible
  1. 执行权限任务后,我使用包含 xcodebuild 命令的 NSTask 执行我的 BuildTask.command 文件。

     NSString *path = [NSString stringWithFormat:@"%@", [[NSBundle mainBundle] pathForResource:@"BuildTask" ofType:@"command"]];
     task.launchPath = path;
     task.arguments = scriptArguments;
     [task launch];
     [task waitUntilExit];
    

在功能中关闭 App Sandbox 时一切正常。当我为 Mac App Store 启用 App Sandbox 时,权限任务给出错误:

chmod: Unable to change file mode on .../MyApp.app/Contents/Resources/BuildTask.command: Operation not permitted

当我在 BuildTask.command 上手动执行 chmod 时,默认情况下 BuildTask.command 中的 write 命令和 xcodebuild 命令会给出如下错误:

defaults[2264:70400] Could not write domain .../SampleApp/SampleApp/SampleApp-Info.plist; exiting

xcodebuild[2410] (FSEvents.framework) FSEventStreamCreate: _FSEventStreamCreate: ERROR: watch_path() failed for '/'
xcodebuild[2410] (FSEvents.framework) FSEventStreamCopyPathsBeingWatched(): failed assertion 'streamRef != NULL'

../MyApp.app/Contents/Resources/BuildTask.command: line 65:  2410 Segmentation fault: 11  xcodebuild -scheme "${SCHEME}" clean build CODE_SIGN_IDENTITY="${SIGNING_IDENTITY}" "${BUILD_ARGUMENT}" "${WORKSPACE_OR_PROJECT}"

那么,我是否有机会向 Mac App Store 发布此工具?

如有任何帮助,我们将不胜感激。

可能不是您想听到的:

  1. The first thing I've done is to get permission to execute "BuildTask.command".

你这里有两个问题。首先,如果您希望从应用程序中更改文件的权限,您应该使用框架或系统调用直接这样做,而不是调用 NSTask 来执行 shell,后者又会执行一个命令调用那些框架或系统调用...

其次,您不应该尝试从应用程序内部更改应用程序包的内容。如果您需要应用程序包中的文件具有执行权限,请在构建应用程序时设置它。您可以在 Xcode.

中的构建阶段执行此操作

So, have I any chance to release this tool to Mac App Store?

很少或none。

Xcode 本身不是沙盒应用程序,您收到的错误消息表明它正在尝试执行违反它从您的应用程序继承的沙盒的操作。

HTH