6

I am making two iPad app that communicate with one file and fetches all the data from one file. I search and find this "containerURLForSecurityApplicationGroupIdentifier" we can create group and store in that. I have write the code below. In entitlement file i write

<?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>$(TeamIdentifierPrefix)com.xxx.catalogapp.Coredata</string>
     </array>
    <key>keychain-access-groups</key>
    <array>
        <string>$(AppIdentifierPrefix)com.xxx.catalogapp.Coredata</string>
    </array>
</dict>
</plist>

And in Code i write this

NSFileManager* fileManager = [NSFileManager defaultManager];
NSURL* storeUrl = [fileManager 
containerURLForSecurityApplicationGroupIdentifier:@"com.xxx.catalogapp.Coredata"];
NSLog(@"%@", storeUrl);

But storeUrl I am getting nil value.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Hitendra
  • 1,610
  • 1
  • 15
  • 22
  • The documentation seems to indicate that you would need the teamIdentifier within the string you sue to access the container. See here in "The application group container directory:" https://developer.apple.com/library/mac/documentation/security/conceptual/AppSandboxDesignGuide/AppSandboxInDepth/AppSandboxInDepth.html – stevesliva Apr 01 '14 at 20:19

4 Answers4

6

Xcode6 (currently in beta) enforces the shared folder IDs to start with "group."

Sharing my CoreData store works for me with the following URL with Xcode6/iOS8 both beta.

NSFileManager* fileManager = [NSFileManager defaultManager];
NSURL* storeUrl = [fileManager containerURLForSecurityApplicationGroupIdentifier:@"group.XXX"];

It seems the documentation that stevesliva linked will be obsolete as soon as Xcode6 will be released

Chris
  • 91
  • 1
  • 3
2

Well, I verified it in my own code. The Team Identifier shows up in the subdirectory of Library/Group Containers, so you do in fact need to include it in your code:

NSFileManager* fileManager = [NSFileManager defaultManager];
NSURL* storeUrl = [fileManager containerURLForSecurityApplicationGroupIdentifier:@"YOURTEAMID.com.xxxxxxxxxxx.catalogapp.Coredata"];
NSLog(@"%@", storeUrl);

What I'm not sure about is whether that's a required name-- it's not very user friendly-- or whether it's something Apple is recommending to make it super-unique.

As mentioned in the comment above, this was figured out starting with Apple's Application Sandbox Design Guide - Application Group Container Directory:

These group containers are automatically added into each app’s sandbox container as determined by the existence of these keys, and are stored in ~/Library/Group Containers/, where is the name of the group. The group name itself must begin with your development team ID, followed by a period.
stevesliva
  • 5,351
  • 1
  • 16
  • 39
  • 1
    This is definitely not the case—shared folder IDs start with "group." and end with the identifier you set up in the iOS Dev portal. – Ben Jackson Aug 12 '14 at 16:45
  • @BenJackson, either the reference cited in my comment on the question, or you are incorrect. I updated the answer with a handy pullquote for you. The answer was perhaps accepted because Hitendra read both the comment and the answer-- the answer was missing info from the comment. – stevesliva Aug 13 '14 at 16:04
2

In iOS 11, there is a better way to get shared container URL.

[NSFileProviderManager defaultManager].documentStorageURL

Randall Wang
  • 1,007
  • 3
  • 10
  • 24
-4

Make sure you're signing both your app and your extension with the same provisioning profile!

JJSaccolo
  • 5,061
  • 2
  • 13
  • 11