kiaraRobles
kiaraRobles

Reputation: 607

How to add files to an App Group shared directory?

So I have an app with a share extension each with their own target. The core of the apps' bundle identifier is com.company.app and the share extensions is com.company.app.share. Each have their own entitlements file, with the core apps being App Groups -> group.com.company.app and the share extension being the same. Both of the bundle identifiers are listed on the apple developer website but for some reason,

I don't seem to have the right permissions to write to the shared private/var/mobile/Containers/Shared/AppGroup/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX/Library/Caches/ directory.

The error message I get is: You don’t have permission to save the file “Caches” in the folder “Library”.

The directory is being saved like this:

GetZipURLInItems(self.extensionContext.inputItems, ^(NSURL *url, NSError *error) {
    if (error == nil) {

        NSURL *containerURL = [[[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:GroupIdentifier] URLByAppendingPathComponent:@"Library/Caches"];
        NSLog(@"EXT: containerURL: %@", containerURL);

        [WPZipArchive unzipFileAtPath:[url path] toDestination:[containerURL absoluteString]];

        [self listDirectoryAtPath:[containerURL absoluteString]];
    }});

What am I'm missing here?

Upvotes: 6

Views: 2627

Answers (1)

kiaraRobles
kiaraRobles

Reputation: 607

The issue was actually using [url absoluteString] vs [url path], changing all the urls to path solved the permissions error.

Upvotes: 9

Related Questions