Is iOS developer able to view file system?

26,342

Solution 1

One can view files in an iOS device but only in that your App's sandbox. Every App has got a Documents, Cache and temp folders. I think the first two are automatically backed up by iTunes when you connect your device, the latter is not backed up.

Example, to get Cache directory path -

- (NSString *)getCacheDirPath
{
    NSString *path = nil;
    NSArray *myPathList = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
    if([myPathList count])
    {
        NSString *bundleName = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleIdentifier"];
        path = [[myPathList objectAtIndex:0] stringByAppendingPathComponent:bundleName];
    }
    return path;
}

To see all files in caches directory -

- (NSMutableArray *)showFiles
{
    NSError *err        = nil;
    NSArray *myPathList = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
    NSString *myPath    = [myPathList  objectAtIndex:0];
    NSArray *dirContent = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:myPath error:&err];
    if(err) NSLog(@"showFiles() - ERROR: %@",[err localizedDescription]);
    NSMutableArray *filePaths  = nil;

    int count = (int)[dirContent count];
    for(int i=0; i<count; i++)
    {
        [filePaths addObject:[dirContent objectAtIndex:i]];
    }
    return filePaths;
}

Solution 2

While the file system on the iDevice is sandboxed, the one in iPhone Simulator is not. You can run your app with the simulator and check the content via:

~/Library/Application Support/iPhone Simulator/5.0/Applications

It should work for your needs.

Solution 3

For device: use the desktop-application iPhone-Explorer it reads the filesystem via USB (It can read and write the entire user-designated zone (applications, music, photos, videos, notes, etc.), but not the entire system unless you jailbreak and install afc2add)

for iPhoneSimulator (like Liz mentioned): ~/Library/Application Support/iPhone Simulator/5.0/Applications

Solution 4

Yeah you can access the filesystem. You are limited to your own application sandbox only however. And you cannot make changes to the app bundle, everything you download as part of the app, this cannot be changed (for security reasons because every app is signed). But you can store files in your app's Documents folder.

Have a look at this lecture, explains everything you need to know:

http://www.stanford.edu/class/cs193p/cgi-bin/drupal/system/files/lectures/09_Data.pdf

Solution 5

If you set a UIFileSharingEnabled key in your plist as true, then you will be able to use iTunes on your Mac to view the file system inside your app's sandboxed Documents directory without additional coding. This won't help if you want to view your Caches directory or look outside your app's sandbox.

Share:
26,342
巫妖王
Author by

巫妖王

Updated on July 09, 2022

Comments

  • 巫妖王
    巫妖王 almost 2 years

    I wonder if developer has some sort of ways to be able to view file system on iOS device like iFile but without jailbreak the device? Need it for devlopement purpose.

    EDIT Thanks for your answers! I know there is a place inside app folder and can be read and write to. But I was looking for a way to view the data quickly without coding, like iFile. So I can check if my write functions suceed or not.