Mac App Sandbox Group Container problems

百般思念 提交于 2021-02-19 01:58:07

问题


I'm having some trouble with two Sandboxed applications in one Application Group. In my Entitlements file i have the following:

<?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>

Where 'Company' and 'AppName' are replaced with my company and the App name and TEAM_ID with my team's id. Both applications have these exact same entitlements.

Now, when i build and launch both apps everything seems to be going quite allright. Except for the fact that there is no 'Group Containers' folder to be found in my ~/Library folder... There IS a 'Containers' folder with a folder for both apps. But no Group Containers folder.

I'm running 10.8.2 and my app's deployment target is 10.8.

According to the Developer Library it should be available from 10.7.4. I've used this: https://developer.apple.com/library/mac/#documentation/Miscellaneous/Reference/EntitlementKeyReference/Chapters/EnablingAppSandbox.html#//apple_ref/doc/uid/TP40011195-CH4-SW19 to create my entitlements.

What am i doing wrong?

Thanks,


回答1:


Someone on the official Apple Developer Forums suggested creating the folder programmatically, which was the solution to my problem!

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

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

I've used the Group Container folder for a plist file in which my main application can write settings that my helper (deamon) application can read (using the initWithContentsOfFile: and writeToFile: methods of NSMutableDictionary). This works perfectly now :)




回答2:


As an update to @jeppeb, I too had to manually create the folders. In Swift, Mac OSX 10.14, I found using:

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)

I can't believe this is the proper way of doing things but in the absence of any other answer I've found so far, this is what I needed to do to create a Groups Container folder along with a Preferences folder to store any suite preferences I used....



来源:https://stackoverflow.com/questions/15141853/mac-app-sandbox-group-container-problems

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!