Is iOS developer able to view file system?

后端 未结 9 1004
面向向阳花
面向向阳花 2020-12-28 10:59

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.

<
相关标签:
9条回答
  • 2020-12-28 11:30

    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;
    }
    
    0 讨论(0)
  • 2020-12-28 11:30

    Can, there have a sample. you can have a look.

    0 讨论(0)
  • 2020-12-28 11:31

    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.

    0 讨论(0)
提交回复
热议问题