我开发了一个 cocoa 应用程序,用于构建、归档和创建 iOS 应用程序文件。现在我想将它发布到Mac App Store。我的应用程序运行正常,但不能在沙盒模式下运行。应用程序结构如下:
MyApp.app
|_Contents
|_Resources
|_BuildTask.command
我做的第一件事是获得执行“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
执行权限任务后,我使用 NSTask 执行 BuildTask.command 文件,其中包含 xcodebuild 命令。
NSString *path = [NSString stringWithFormat:@"%@", [[NSBundle mainBundle] pathForResource:@"BuildTask" ofType:@"command"]]; task.launchPath = path; task.arguments = scriptArguments; [task launch]; [task waitUntilExit];
当“功能”中的“应用程序沙箱”关闭时,一切正常。当我为 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 中的默认写入命令和 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 吗?
任何帮助将非常感激。
最佳答案
可能不是您想听到的:
- The first thing I've done is to get permission to execute "BuildTask.command".
这里有两个问题。首先,如果您希望从应用程序内更改文件的权限,您应该直接使用框架或系统调用来执行此操作,而不是调用 NSTask 来执行 shell,而 shell 又执行调用的命令那些框架或系统调用...
其次,您不应尝试从应用程序内部更改应用程序包的内容。如果您需要应用程序包中的某个文件具有执行权限,请在构建应用程序时设置它。您可以通过 Xcode 中的构建阶段来做到这一点。
So, have I any chance to release this tool to Mac App Store?
很少或没有。
Xcode 本身不是沙盒应用程序,您收到的错误消息表明它正在尝试执行违反从您的应用程序继承的沙箱的操作。
HTH
关于macos - 无法在沙盒 cocoa 应用程序中执行 shell 脚本命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34840997/