本文介绍了iOS开发者是否可以查看文件系统?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不知开发者是否有某种方式可以在iFile等iOS设备上查看文件系统,但是没有越狱的设备?
需要它的行为目的。

编辑
感谢您的回答!我知道app文件夹内有一个地方,可以读写。
但我正在寻找一种快速查看数据的方式,无需编码,如iFile。所以,我可以检查我的写功能是否suceed。

解决方案

可以查看iOS设备中的文件,但只有在应用程序的沙箱。每个App都有一个 Documents Cache temp 文件夹。我想前两个是在你连接你的设备的时候自动备份的,而后者是不会备份的。



例子,获取缓存目录路径 -

   - (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];
}
返回路径;

$ / code>

查看 caches中的所有文件 $ b $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $'
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]];
}
返回filePaths;
}


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.

EDITThanks 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.

解决方案

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;
}

这篇关于iOS开发者是否可以查看文件系统?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 20:31