[英]Can't execute shell script commands in sandboxed cocoa app
I developed a cocoa application that builds, archives and creates iOS application files. 我开发了一个构建,存档和创建iOS应用程序文件的cocoa应用程序。 Now I want to release it to Mac App Store.
现在我想将它发布到Mac App Store。 My app runs correctly, but not in sandbox mode.
我的应用运行正常,但不是沙盒模式。 App structure is as following:
App结构如下:
MyApp.app
|_Contents
|_Resources
|_BuildTask.command
The first thing I've done is to get permission to execute "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];
Otherwise, BuildTask produces an error: 否则,BuildTask会产生错误:
Problem Running Task: launch path not accessible
After executing the permission task, I execute my BuildTask.command file with NSTask that includes xcodebuild commands in it. 执行权限任务后,我使用包含xcodebuild命令的NSTask执行我的BuildTask.command文件。
NSString *path = [NSString stringWithFormat:@"%@", [[NSBundle mainBundle] pathForResource:@"BuildTask" ofType:@"command"]]; task.launchPath = path; task.arguments = scriptArguments; [task launch]; [task waitUntilExit];
Everything is OK when App Sandbox is off in Capabilities. 当App Sandbox在功能中关闭时,一切正常。 When I enable App Sandbox for Mac App Store, permission task gives error:
当我启用App Sandbox for Mac App Store时,权限任务会出错:
chmod: Unable to change file mode on .../MyApp.app/Contents/Resources/BuildTask.command: Operation not permitted
When I execute chmod on BuildTask.command manually, defaults write commands and xcodebuild commands in BuildTask.command give errors like: 当我手动在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}"
So, have I any chance to release this tool to Mac App Store? 那么,我有机会将此工具发布到Mac App Store吗?
Any help would really appreciated. 任何帮助都会非常感激。
Probably not what you want to hear: 可能不是你想听到的:
- The first thing I've done is to get permission to execute "BuildTask.command".
我做的第一件事就是获得执行“BuildTask.command”的权限。
You have two problems here. 你有两个问题。 First if you wish to change the permissions on a file from within an app you should be using framework or system calls to do so directly, not calling
NSTask
to execute a shell which in turn executes a command which calls those framework or system calls... 首先,如果您希望从应用程序中更改文件的权限,您应该使用框架或系统调用直接执行此操作,而不是调用
NSTask
来执行shell,而shell又执行调用这些框架或系统调用的命令。 。
Second you should not be trying to change the contents of your application bundle from within the application. 其次,您不应该尝试从应用程序中更改应用程序包的内容。 If you need a file in your application bundle to have execute permission then set it when you build the app.
如果您需要应用程序包中的文件具有执行权限,请在构建应用程序时进行设置。 You can do that with a build phase in Xcode.
您可以使用Xcode中的构建阶段来完成此操作。
So, have I any chance to release this tool to Mac App Store?
那么,我有机会将此工具发布到Mac App Store吗?
Little or none. 很少或没有。
Xcode itself is not a sandboxed application and the error messages you are getting indicate that it is trying to do operations which violate the sandbox it has inherited from your app. Xcode本身不是沙盒应用程序,您收到的错误消息表明它正在尝试执行违反从您的应用程序继承的沙箱的操作。
HTH HTH
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.