How to add files to an App Group shared directory?
Asked Answered
S

1

6

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?

Solidarity answered 15/11, 2016 at 19:15 Comment(3)
How are you trying to write to it? Look at using NSFileManager:containerURLForSecurityApplicationGroupIdentifierHeard
@Essenceofchickens I updated the original question to show how I'm saving the dir.Solidarity
Have you tried it without the URLByAppendingPathComponent: part?Heard
S
9

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

Solidarity answered 15/11, 2016 at 20:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.