我有一个SQLite数据库,我用它来存储应用程序数据,我可以查看它内部以调试我遇到的问题-但是iPhone模拟器通常在哪里存储它的数据?


当前回答

在Xcode 5中,你可以使用以下代码:

#import <Foundation/NSFileManager.h>

and:

NSString *homeDir = NSHomeDirectory();
NSLog(@"%@",homeDir);

结果看起来像这样:

"/Users/<your user name>/Library/Application Support/iPhone Simulator/7.1/Applications/hhhhhhhh-hhhh-hhhh-hhhh-hhhhhhhhhhhh"

hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh是一个十六进制字符串,用来识别你的iOS应用程序。

其他回答

Xcode在哪里存储模拟器和运行时

运行时

$ open ~/Library/Developer/CoreSimulator/Profiles/Runtimes

例如:iOS 13.0, watchOS 6.0。到目前为止,这些占用的空间最多。每一个都可以达到~5GB

设备

$ open ~/Library/Developer/CoreSimulator/Devices

例如:iPhone Xr, iPhone 11 Pro Max。这些文件通常都小于15 mb。

解释

模拟器在运行时和设备之间被分割。如果您运行$ xcrun simctl list,您可以看到概览,但是如果您想找到这些模拟器的物理位置,请查看我所展示的这些目录。

删除您不支持的运行时是完全安全的。如果您愿意,可以稍后重新安装。

发现:

~/Library/Application Support/iPhone Simulator/User/

在Lion上,Users/[username]/Library被隐藏。

要在Finder中查看,单击屏幕顶部的“Go”菜单,并按住“alt”键显示“Library”。

点击“Library”,你可以看到之前隐藏的库文件夹。

先前的建议:

Use

chflags nohidden /users/[username]/library

在终端中显示文件夹。

还有另一种(更快的?)方法可以在没有终端的情况下找到你的应用数据:

在模拟器中启动应用程序 开放活动监视器 在CPU选项卡中找到应用程序的名称 双击打开“打开文件和端口”

您可以尝试使用下面的代码

NSString *fileName = @"Demo.pdf";
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *pdfFileName = [documentsDirectory stringByAppendingPathComponent:fileName];
    NSLog(@"File path%@",pdfFileName);