我有一个SQLite数据库,用于存储应用程序数据,我需要查看其中的内容以调试遇到的问题。但是iPhone模拟器通常将其数据存储在哪个位置呢?
我有一个SQLite数据库,用于存储应用程序数据,我需要查看其中的内容以调试遇到的问题。但是iPhone模拟器通常将其数据存储在哪个位置呢?
$ 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
,您可以看到概述,但如果您想找到这些模拟器的实际位置,请查看我展示的这些目录。
完全可以删除不支持的运行时。如果需要,稍后可以重新安装它们。
只需这样做:
NSString *docDirPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)objectAtIndex:0];
NSLog(@"%@", docDirPath);
然后您将会得到类似于这样的东西:
/Users/admin/Library/Developer/CoreSimulator/Devices/58B5B431-D2BB-46F1-AFF3-DFC789D189E8/data/Containers/Data/Application/6F3B985F-351E-468F-9CFD-BCBE217A25FB/Documents
前往该路径,您将无论使用哪个版本的XCode都能看到您的应用程序的文档文件夹。(在Finder中使用“前往文件夹...”命令并指定路径“~/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 4.6中存储路径如下:
/Users/[currentuser]/Library/Application Support/iPhone Simulator/6.1/Applications/
可使用以下代码来编程了解它:
NSLog(@"path:%@",[[NSBundle mainBundle]bundlePath]);
print("路径:\(NSBundle.mainBundle().bundlePath)")
- SwiftArchitectiOS 8版本
要定位文档文件夹,您可以将文件写入文档文件夹中:
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
对于 macOS Catalina,我发现我的数据库在:
~/Library/Developer/CoreSimulator/Devices/{deviceId}/data/Containers/Data/Application/{applicationId}/Documents/my.db
applicationId
,我只是按修改日期对文件夹进行排序,不过我相信有更好的方法来做到这一点。对于不经常使用Xcode的react-native用户,可以使用find
。打开终端并通过数据库名称搜索。
$ find ~/Library/Developer -name 'myname.db'
如果您不知道确切的名称,可以使用通配符:
$ find ~/Library/Developer -name 'myname.*'
最初的回答。
如果在Lion操作系统中,任何人仍然遇到这个问题,可以阅读一篇非常好的文章,其中包含19种不同的提示,用于查看您的~/Library目录。文章由Dan Frakes撰写,您可以在此链接找到它。
请记住,模拟器的目录如下:
~/Library/Application Support/iPhone Simulator/User/
您可以尝试使用以下代码
NSString *fileName = @"Demo.pdf";
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *pdfFileName = [documentsDirectory stringByAppendingPathComponent:fileName];
NSLog(@"File path%@",pdfFileName);