Sunday, April 21, 2013

NSFileManager containerURLForSecurityApplicationGroupIdentifier example objc


containerURLForSecurityApplicationGroupIdentifier:

Returns the container directory associated with the specified security application group ID.
- (NSURL *)containerURLForSecurityApplicationGroupIdentifier:(NSString *)groupIdentifier
Discussion
As explained in App Sandbox Design Guide, groups of sandboxed apps that need to share files and other information can request a container directory as part of their entitlements. These directories are stored in~/Library/Group Containers/.
[NSFileManager containerURLForSecurityApplicationGroupIdentifier]
When called with a valid group identifier, this method returns the location of that directory as an NSURLobject. This method also creates the directory if it does not yet exist.


Example of [NSFileManager containerURLForSecurityApplicationGroupIdentifier]
Listing 2-1  Creating an app group container directory
    NSFileManager *fm = [NSFileManager defaultManager];
    NSString *appGroupName = @"Z123456789.com.example.app-group"; /* For example */
 
    NSURL *groupContainerURL = [fm containerURLForSecurityApplicationGroupIdentifier:appGroupName];
    NSError* theError = nil;
    if (![fm createDirectoryAtURL: groupContainerURL withIntermediateDirectories:YES attributes:nil error:&theError]) {
        // Handle the error.
    }