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


当前回答

iOS 8

要找到Documents文件夹,你可以在Documents文件夹中写入一个文件:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *fileName = [documentsDirectory stringByAppendingPathComponent:@"Words.txt"];
NSString *content = @"Apple";
[content writeToFile:fileName atomically:NO encoding:NSStringEncodingConversionAllowLossy error:nil];

例如,在didFinishLaunchingWithOptions中。

然后你可以打开一个终端,找到这个文件夹:

$ find ~/Library -name Words.txt

其他回答

iOS 8

要找到Documents文件夹,你可以在Documents文件夹中写入一个文件:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *fileName = [documentsDirectory stringByAppendingPathComponent:@"Words.txt"];
NSString *content = @"Apple";
[content writeToFile:fileName atomically:NO encoding:NSStringEncodingConversionAllowLossy error:nil];

例如,在didFinishLaunchingWithOptions中。

然后你可以打开一个终端,找到这个文件夹:

$ find ~/Library -name Words.txt

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

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的react原生用户,你可以使用find。打开终端,通过数据库名称进行搜索。

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

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

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

对于Xcode 4.6,它被存储在以下路径…

/Users/[currentuser]/Library/Application Support/iPhone Simulator/6.1/Applications/

要通过编程方式了解它,请使用以下代码

  NSLog(@"path:%@",[[NSBundle mainBundle]bundlePath]);

为Xcode6 - iOS8 +

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

接受的答案对于SDK 3.2是正确的- SDK 4用它可以模拟的每个遗留的iPhone OS/iOS版本的数字替换该路径中的/User文件夹,因此路径变成:

~/Library/Application Support/iPhone Simulator/[OS version]/Applications/[appGUID]/

如果你安装了之前的SDK,它是3.1。X模拟器将继续将其数据保存在:

~/Library/Application Support/iPhone Simulator/User/Applications/[appGUID]/