Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 495
kiaraRobles Avatar asked Nov 15 '16 19:11

kiaraRobles


1 Answers

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

like image 100
kiaraRobles Avatar answered Sep 30 '22 16:09

kiaraRobles