简体   繁体   中英

How can I view the contents of the App Group Shared Container directory when debugging an iOS app?

Fairly self explanatory.

We can view the app's documents, library, tmp directories via Window > Devices (this has been the case forever).

But when app extensions came on the scene with iOS8, the App Group shared container came with them. How can I view its contents?

Edit: to clarify, I'm not asking how to interact with this directory in code. I'm asking about how to interact with this directory in the context of Finder.

Get App Group Path

#define APP_GROUP_PATH [[[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:@"yourGrpupId"] path]

Following code to view Shared container data

NSLog(@"Shared container data:%@",[self listFileAtPath:APP_GROUP_PATH]);

-(NSArray *)listFileAtPath:(NSString *)path
{
    int count;

    NSArray *directoryContent = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:path error:NULL];
    for (count = 0; count < (int)[directoryContent count]; count++)
    {
        NSLog(@"File %d: %@", (count + 1), [directoryContent objectAtIndex:count]);
    }
    return directoryContent;
}

You can't exactly interact with it in a finder way. Altough you can view the container and download it.

  1. Go to Devices and select the device
  2. You can download the container with the three dotted button under the app that has the container setup.

You can also show or download the container.

You can print the path to the directory in your code, then open the path in finder using Shift + CMD + G .

print(urlToAFileInTheDirectory.absoluteString)

where urlToAFileInTheDirectory is a URL that contains the path to a file in the shared documents directory.

This works in the simulator in Xcode 13. I'm not sure if it works on an actual device.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM