我有一个SQLite数据库,我用它来存储应用程序数据,我可以查看它内部以调试我遇到的问题-但是iPhone模拟器通常在哪里存储它的数据?
当前回答
简单地这样做:
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)
其他回答
您可以尝试使用下面的代码
NSString *fileName = @"Demo.pdf";
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *pdfFileName = [documentsDirectory stringByAppendingPathComponent:fileName];
NSLog(@"File path%@",pdfFileName);
还有另一种(更快的?)方法可以在没有终端的情况下找到你的应用数据:
在模拟器中启动应用程序 开放活动监视器 在CPU选项卡中找到应用程序的名称 双击打开“打开文件和端口”
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中构建的应用程序所在的目录,请执行以下操作:
打开Finder窗口(笑脸图标) 然后点击GO ->进入文件夹 类型:~/Library/Application Support/iPhone Simulator 目录是不同模拟器的iOS版本 子目录是安装在模拟器上的应用程序 文档文件夹是用户生成的内容备份到iCloud的地方
推荐文章
- Ios模拟器:如何关闭应用程序
- 如何在iOS中使用Swift编程segue
- 我如何改变UIButton标题颜色?
- Xcode 4挂在“附加到(应用程序名称)”
- 缺少推荐的图标文件-该包不包含iPhone / iPod Touch的应用程序图标,像素为“120x120”,png格式
- 如何使用Xcode创建。ipa文件?
- 我可以在没有“构建和运行”的情况下启动iPhone模拟器吗?
- Xcode 4 -在新的Macintosh安装上的配置文件上“没有找到有效的签名标识”错误
- 在iPhone上确定用户是否启用了推送通知
- 是否有可能禁用浮动头在UITableView与UITableViewStylePlain?
- Swift -转换为绝对值
- 在代码中为UIButton设置一个图像
- 如何修复UITableView分隔符在iOS 7?
- 如何改变时间和时区在iPhone模拟器?
- 在Swift中根据字符串计算UILabel的大小