使用COMMAND LINE帮助程序的沙盒OSX应用程序无法获得根路径'

时间:2015-03-26 15:40:36

标签: macos sandbox code-signing mac-app-store

我正在构建一个与命令工具'unrar'捆绑在一起的Mac应用程序来解开一些文件。该应用程序是沙盒。

在xcode中,我将unrar命令工具复制到应用程序的Resourse文件夹(带有名为'exec'的子路径):

复制文件 目的地:资源 - 子路径:执行

在复制阶段之后,我执行运行脚本来设置权利和代码签名,如下所示:

运行脚本: Shell:/ bin / sh

LOCATION="${BUILT_PRODUCTS_DIR}"/"${CONTENTS_FOLDER_PATH}"
IDENTITY="3rd Party Mac Developer Application: CompanyName."
codesign -f -s "$IDENTITY" --entitlements"/<path>/unrar.entitlements" "$LOCATION"/Resources/exec/unrar

在应用程序本身中,我使用NSTask来执行unrar命令:

NSString *filePath = [[NSBundle mainBundle] pathForResource:@"unrar" ofType:@"" inDirectory:@"exec"];

NSTask *task = [[NSTask alloc] init];
[task setLaunchPath:filePath];
[task setArguments:[NSArray arrayWithObjects:@"e", rarfilepath,extractpath, nil]];
[_task launch];

unrar.entitlements包含:

<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.inherit</key>
<true/>

运行应用程序时,一切正常,文件被解压缩。

但是......当我检查系统日志时,我看到以下消息:

secinitd [332]:unrar [94747]:无法获取主可执行文件包的根路径:/Applications/App.app/Contents/Resources/exec/unrar

当我没有运行上面的运行脚本时,消息确实消失了,但是没有为'unrar'命令工具设置权利并且Sandboxing失败。

我现在已经听了三天这个消息意味着什么以及如何解决它,但是我没有想法。

搜索google或stackoverflow也无济于事。

请有人帮我解决这个问题。

谢谢你, 安德烈。

(对不起所有文字,但我不允许发布图片。)

2 个答案:

答案 0 :(得分:0)

我认为unrar可执行文件必须位于

MySandboxApp.app/Contents/Helpers/unrar

Resources文件夹仅限于不可执行的内容。

答案 1 :(得分:0)

我一直将我的主要和辅助二进制可执行文件放在Contents/MacOS中,但是Contents/Helpers也一样。

这些文件夹专门包含Mach-O可执行二进制文件:

Folder Executable  
_______________________________________________________________________
Contents Top content directory of the bundle
       Contents/MacOS Helper apps and tools
       Contents/Frameworks Frameworks, dylibs
       Contents/PlugIns Plug-ins, both loadable and Extensions
       Contents/XPCServices XPC services
       Contents/Helpers Helper apps and tools
       Contents/Library/Automator Automator actions
       Contents/Library/Spotlight Spotlight importers
       Contents/Library/LoginItems Installable login items
       Contents/Library/LaunchServices Privileged helpers installed by ServiceManagement

其他文件夹,例如Contents/Resources用于非二进制执行文件,例如脚本和数据文件。

相关问题