iOS 开发者可以查看文件系统吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7377280/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 21:27:31  来源:igfitidea点击:

Is iOS developer able to view file system?

iphoneiosobjective-cfilesystems

提问by u780463

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.

我想知道开发人员是否有某种方法可以在不越狱设备的情况下查看 iFile 等 iOS 设备上的文件系统?出于开发目的需要它。

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.

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

采纳答案by Srikar Appalaraju

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

可以在 iOS 设备中查看文件,但只能在应用程序的沙箱中查看。每个应用程序都有一个Documents,Cachetemp文件夹。我认为当您连接设备时,iTunes 会自动备份前两个,后者不会备份。

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 cachesdirectory -

要查看caches目录中的所有文件-

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

回答by Liz

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:

虽然 iDevice 上的文件系统是沙盒的,但 iPhone Simulator 中的文件系统不是。您可以使用模拟器运行您的应用程序并通过以下方式检查内容:

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

It should work for your needs.

它应该适合您的需求。

回答by thomas

For device: use the desktop-application iPhone-Explorerit 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)

对于设备:使用桌面应用程序iPhone-Explorer它通过 USB 读取文件系统(它可以读取和写入整个用户指定的区域(应用程序、音乐、照片、视频、笔记等),但不能读取和写入整个系统,除非你越狱并安装afc2add)

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

对于 iPhoneSimulator(如 Liz 提到的): ~/Library/Application Support/iPhone Simulator/5.0/Applications

回答by lms

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.

是的,您可以访问文件系统。但是,您只能使用自己的应用程序沙箱。并且您无法更改应用程序包,您作为应用程序的一部分下载的所有内容都无法更改(出于安全原因,因为每个应用程序都已签名)。但是您可以将文件存储在应用程序的 Documents 文件夹中。

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

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

回答by hotpaw2

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.

如果您将 plist 中的 UIFileSharingEnabled 键设置为 true,那么您将能够在 Mac 上使用 iTunes 来查看应用程序沙盒文档目录中的文件系统,而无需额外编码。如果您想查看 Caches 目录或查看应用程序沙箱之外的内容,这将无济于事。

回答by user501836

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

可以,有样品。你可以看看。

回答by Chris W. Rea

When your iOS device is connected to your computer and correctly provisioned for development, you can use Xcode 4 to download files for your own projects, and not only the files in the Documentsdirectory.

当您的 iOS 设备连接到您的计算机并正确配置用于开发时,您可以使用 Xcode 4 为您自己的项目下载文件,而不仅仅是Documents目录中的文件

Refer to this other answer: How to download app data in Xcode 4.2

请参阅其他答案: 如何在 Xcode 4.2 中下载应用程序数据

回答by Cian

Yes lms is correct. Apple has limited the file access to just the app itself's (Document directory). So there is no other way of accessing it. I faced this issue in one of my projects and I started developing the full file accessing system. All operations are supported like iFile. You can do everything similarly as iFile app visually.

是的 lms 是正确的。Apple 已将文件访问权限限制为仅应用程序本身的(文档目录)。所以没有其他方法可以访问它。我在我的一个项目中遇到了这个问题,我开始开发完整的文件访问系统。像 iFile 一样支持所有操作。您可以在视觉上与 iFile 应用程序类似地执行所有操作。

https://github.com/CianApple/FileSystem

https://github.com/CianApple/FileSystem

I have posted the project on github for public. Feel free to use it. It might help you with your issue.

我已将该项目发布在 github 上以供公众使用。随意使用它。它可能会帮助您解决您的问题。

回答by Jakob

itools is a little tool that works around apples efforts to protect the iPhone. it therefor might infringe with some of apples policies but does the job

itools 是一个小工具,可以解决苹果保护 iPhone 的努力。因此,它可能会违反苹果的某些政策,但确实有效