Mac App Sandbox Group容器问题

时间:2013-02-28 17:27:25

标签: objective-c xcode cocoa appstore-sandbox

我在一个应用程序组中遇到了两个沙盒应用程序的问题。在我的Entitlements文件中,我有以下内容:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/    PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
     <key>com.apple.security.app-sandbox</key>
     <true/>

     <key>com.apple.security.application-groups</key>
     <array>
          <string>TEAM_ID.com.Company.AppName</string>
     </array>
</dict>
</plist>

'Company'和'AppName'被我的公司替换,App名称和TEAM_ID被我的团队ID替换。两个应用程序都具有这些完全相同的权利。

现在,当我构建并启动这两个应用程序时,一切似乎都很顺利。除了在我的〜/ Library文件夹中找不到“Group Containers”文件夹之外......还有一个'Containers'文件夹,其中包含两个应用程序的文件夹。但没有Group Containers文件夹。

我正在运行10.8.2,我的应用部署目标是10.8。

根据开发人员库,它应该可以从10.7.4获得。我使用了这个:https://developer.apple.com/library/mac/#documentation/Miscellaneous/Reference/EntitlementKeyReference/Chapters/EnablingAppSandbox.html#//apple_ref/doc/uid/TP40011195-CH4-SW19来创建我的权利。

我做错了什么?

谢谢,

2 个答案:

答案 0 :(得分:3)

官方Apple Developer Forums上有人建议以编程方式创建文件夹,这是解决我的问题的方法!

NSString *groupContainer = [@"~/../../../Group Containers/TEAM_ID.com.Company.AppName" stringByExpandingTildeInPath];

[[NSFileManager defaultManager] createDirectoryAtPath:groupContainer withIntermediateDirectories:YES attributes:nil error:NULL]]

我已经将组容器文件夹用于plist文件,其中我的主应用程序可以编写我的帮助程序(deamon)应用程序可以读取的设置(使用initWithContentsOfFile:和NSMutableDictionary的writeToFile:方法)。这现在完美地工作:)

答案 1 :(得分:0)

作为@jeppeb的更新,我也不得不手动创建文件夹。在Swift,Mac OSX 10.14中,我发现使用:

let appSupport: String = NSString(string: "~/Library/Group Containers/com.myCo.myAppName/Library/Application Support").expandingTildeInPath
try fileMan.createDirectory(atPath: appSupport, withIntermediateDirectories: true, attributes: nil)

let caches: String = NSString(string: "~/Library/Group Containers/com.myCo.myAppName/Library/Caches/myCacheFolder").expandingTildeInPath
try fileMan.createDirectory(atPath: caches, withIntermediateDirectories: true, attributes: nil)

let prefs: String = NSString(string: "~/Library/Group Containers/com.myCo.myAppName/Library/Preferences").expandingTildeInPath
try fileMan.createDirectory(atPath: prefs, withIntermediateDirectories: true, attributes: nil)

我不敢相信这是正确的处理方式,但是到目前为止我还没有找到其他答案,这就是我需要创建Groups Container文件夹以及Preferences文件夹来完成的工作存储我使用的所有套件首选项。...