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


当前回答

如果模拟器正在运行,你可以得到任何应用程序的容器的路径:

xcrun simctl get_app_container booted <app bundle identifier>

示例输出:

$ xcrun simctl get_app_container booted com.example.app
/Users/jappleseed/Library/Developer/CoreSimulator/Devices/7FB6CB8F-63CB-4F27-BDAB-884814DA6FE0/data/Containers/Bundle/Application/466AE987-76BC-47CF-A207-266E65E7DE0A/example.app

在任何需要设备UDID的地方,“boot”都可以替换为大多数simctl命令。

您可以使用xcrun simctl list查看设备列表,并使用xcrun simctl help获取有关特定命令的帮助。

更新:在Xcode 8.3中,你现在可以通过添加"app"、"data"、"groups"或应用组标识符来指定你想要的容器类型。

获取数据容器:

$ xcrun simctl get_app_container booted com.example.app data

其他回答

看起来Xcode 6.0再次移动了这个位置,至少iOS 8模拟器是这样的。

~ /图书馆/开发/ CoreSimulator /设备/[的DeviceID] /数据/集装箱/数据/应用程序/ [AppID]

如果有人仍然在lion中遇到这个问题,有一篇很棒的文章提供了19个查看~/Library目录的技巧。在这里找到Dan Frakes的文章http://www.macworld.com/article/161156/2011/07/view_library_folder_in_lion.html

记住模拟器的目录如下所示

~/库/应用程序支持/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应用程序。

简单地这样做:

NSString *docDirPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)objectAtIndex:0];
NSLog(@"%@", docDirPath);

你会得到这样的想法:

/用户/ admin /图书馆/开发/ CoreSimulator /设备/ 58 b5b431-d2bb-46f1-aff3-dfc789d189e8 /数据/集装箱/数据/应用程序/ 6 f3b985f - 351 - e - 468 - f - 9 - cfd bcbe217a25fb /文档

去那里,你会看到应用的文档文件夹,不管XCode的版本是什么。(在Finder中使用“Go to Folder…”命令并指定路径“~/library”)。

字符串路径的Swift版本:

let docDirPath =
NSSearchPathForDirectoriesInDomains(.documentDirectory,
                                    .userDomainMask, true).first
print(docDirPath)

和文件夹URL:

let docDirUrl =
    FileManager.default.urls(for: .documentDirectory,
                             in: .userDomainMask).first
print(docDirUrl)

对于不经常使用Xcode的react原生用户,你可以使用find。打开终端,通过数据库名称进行搜索。

$ find ~/Library/Developer -name 'myname.db'

如果你不知道确切的名称,你可以使用通配符:

$ find ~/库/开发人员名'myname.*'