iOS 7中,iOS模拟器的文档目录可以在以下位置找到:
/Users/Sabo/Library/Application Support/iPhone Simulator/
然而,在中,我找不到上面目录中对应 iOS 8 的文件目录。
那么 iOS 8 模拟器的文档目录路径在哪里?
iOS 7中,iOS模拟器的文档目录可以在以下位置找到:
/Users/Sabo/Library/Application Support/iPhone Simulator/
然而,在中,我找不到上面目录中对应 iOS 8 的文件目录。
那么 iOS 8 模拟器的文档目录路径在哪里?
使用Xcode 6.0中的CoreSimulator后,数据目录是按设备而不是按版本进行管理的。数据目录为~/Library/Developer/CoreSimulator/Devices/<设备ID>/data,其中<设备ID>可以从'xcrun simctl list'命令中获取。
如果您不计划回滚到Xcode 5.x或更早版本,则可以安全地删除~/Library/Application Support/iPhone Simulator和~/Library/Logs/iOS Simulator。
当我使用CoreData存储完整路径时,遇到了同样的问题。在检索完整路径时,会返回null,因为每次应用程序重新启动时文档文件夹UUID都不同。以下是我的解决方案:
[[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
将步骤2和步骤1连接起来,以获取所需检索的文档/文件的完整路径。 您可以参考苹果开发者笔记:https://developer.apple.com/library/ios/technotes/tn2406/_index.html
尝试使用~/Library/Developer/CoreSimulator/Devices/
参考Ankur的答案,但是对于我们Swift用户:
let urls = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)
println("Possible sqlite file: \(urls)")
模拟器位于:
~/Library/Developer/CoreSimulator/
在此处,它们被列为UUID名称的目录。使用“日期修改时间”排序以找到最新的模拟器。在里面导航到:
/data/Containers/Data/Application/
这里您将获得该设备上所有应用程序的列表。您可以再次对其进行排序以获取最新的应用程序。
注意:每次运行应用程序时,Xcode都会更改目录名称,因此不要依赖于在桌面上制作别名/快捷方式。
最简单的方法是使用此处的应用程序,它会自动完成所有操作。
iOS 8模拟器中的文档目录在哪里?
您可能已经注意到,随着Xcode 6的推出,iPhone模拟器也做了一些更改,其中当然包括模拟应用的文档目录路径。有时候我们需要查看它。
找到文档路径并不像以前那么容易,即 Library/Application Support/iPhone Simulator/7.1/Applications/后面跟着一个代表您的应用程序的加密数字。
从Xcode 6和iOS 8开始,您可以在这里找到它:Library/Developer/CoreSimulator/Devices/加密数字/data/Containers/Data/Application/加密数字
http://pinkstone.co.uk/where-is-the-documents-directory-for-the-ios-8-simulator/
在Appdelegate中,放置以下代码以查看文档和缓存目录:
#if TARGET_IPHONE_SIMULATOR
NSLog(@"Documents Directory: %@", [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject]);
NSArray* cachePathArray = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString* cachePath = [cachePathArray lastObject];
NSLog(@"Cache Directory: %@", cachePath);
#endif
关于日志:
文档目录:/Users/xxx/Library/Developer/CoreSimulator/Devices/F90BBF76-C3F8-4040-9C1E-448FAE38FA5E/data/Containers/Data/Application/3F3F6E12-EDD4-4C46-BFC3-58EB64D4BCCB/Documents/
缓存目录:/Users/xxx/Library/Developer/CoreSimulator/Devices/F90BBF76-C3F8-4040-9C1E-448FAE38FA5E/data/Containers/Data/Application/3F3F6E12-EDD4-4C46-BFC3-58EB64D4BCCB/Library/Caches
$ cd ~/iosapps
$ ./app.sh
$ ls -l
total 152
lrwxr-xr-x 1 me staff 72 Nov 14 17:15 My App Beta-iOS-7-1_iPad-Retina.iapp -> iOS-7-1_iPad-Retina.dr/Applications/BD660795-9131-4A5A-9A5D-074459F6A4BF
lrwxr-xr-x 1 me staff 72 Nov 14 17:15 Other App Beta-iOS-7-1_iPad-Retina.iapp -> iOS-7-1_iPad-Retina.dr/Applications/A74C9F8B-37E0-4D89-80F9-48A15599D404
lrwxr-xr-x 1 me staff 72 Nov 14 17:15 My App-iOS-7-1_iPad-Retina.iapp -> iOS-7-1_iPad-Retina.dr/Applications/07BA5718-CF3B-42C7-B501-762E02F9756E
lrwxr-xr-x 1 me staff 72 Nov 14 17:15 Other App-iOS-7-1_iPad-Retina.iapp -> iOS-7-1_iPad-Retina.dr/Applications/5A4642A4-B598-429F-ADC9-BB15D5CEE9B0
-rwxr-xr-x 1 me staff 3282 Nov 14 17:04 app.sh
lrwxr-xr-x 1 me staff 158 Nov 14 17:15 com.mycompany.app1-iOS-8-0_iPad-Retina.iapp -> /Users/me/Library/Developer/CoreSimulator/Devices/129FE671-F8D2-446D-9B69-DE56F1AC80B9/data/Containers/Data/Application/69F7E3EF-B450-4840-826D-3830E79C247A
lrwxr-xr-x 1 me staff 158 Nov 14 17:15 com.mycompany.app1-iOS-8-1_iPad-Retina.iapp -> /Users/me/Library/Developer/CoreSimulator/Devices/414E8875-8875-4088-B17A-200202219A34/data/Containers/Data/Application/976D1E91-DA9E-4DA0-800D-52D1AE527AC6
lrwxr-xr-x 1 me staff 158 Nov 14 17:15 com.mycompany.app1beta-iOS-8-0_iPad-Retina.iapp -> /Users/me/Library/Developer/CoreSimulator/Devices/129FE671-F8D2-446D-9B69-DE56F1AC80B9/data/Containers/Data/Application/473F8259-EE11-4417-B04E-6FBA7BF2ED05
lrwxr-xr-x 1 me staff 158 Nov 14 17:15 com.mycompany.app1beta-iOS-8-1_iPad-Retina.iapp -> /Users/me/Library/Developer/CoreSimulator/Devices/414E8875-8875-4088-B17A-200202219A34/data/Containers/Data/Application/CB21C38E-B978-4B8F-99D1-EAC7F10BD894
lrwxr-xr-x 1 me staff 158 Nov 14 17:15 com.mycompany.otherapp-iOS-8-1_iPad-Retina.iapp -> /Users/me/Library/Developer/CoreSimulator/Devices/414E8875-8875-4088-B17A-200202219A34/data/Containers/Data/Application/DE3FF8F1-303D-41FA-AD8D-43B22DDADCDE
lrwxr-xr-x 1 me staff 51 Nov 14 17:15 iOS-7-1_iPad-Retina.dr -> simulator/4DC11775-F2B5-4447-98EB-FC5C1DB562AD/data
lrwxr-xr-x 1 me staff 51 Nov 14 17:15 iOS-8-0_iPad-2.dr -> simulator/6FC02AE7-27B4-4DBF-92F1-CCFEBDCAC5EE/data
lrwxr-xr-x 1 me staff 51 Nov 14 17:15 iOS-8-0_iPad-Retina.dr -> simulator/129FE671-F8D2-446D-9B69-DE56F1AC80B9/data
lrwxr-xr-x 1 me staff 51 Nov 14 17:15 iOS-8-1_iPad-Retina.dr -> simulator/414E8875-8875-4088-B17A-200202219A34/data
lrwxr-xr-x 1 me staff 158 Nov 14 17:15 org.cocoapods.demo.pajdeg-iOS-8-0_iPad-Retina.iapp -> /Users/me/Library/Developer/CoreSimulator/Devices/129FE671-F8D2-446D-9B69-DE56F1AC80B9/data/Containers/Data/Application/C3069623-D55D-462C-82E0-E896C942F7DE
lrwxr-xr-x 1 me staff 51 Nov 14 17:15 simulator -> /Users/me/Library/Developer/CoreSimulator/Devices
./app.sh
部分同步链接。现在基本上总是必要的,因为自Xcode 6.0以来,每次运行时应用程序会更改UUID。此外,遗憾的是,8.x按bundle id进行应用分类,而< 8则按应用程序名称分类。
适用于 Swift 3.x
if let documentsPath = FileManager.default.urls(for:.documentDirectory, in: .userDomainMask).first?.path {
print("Documents Directory: " + documentsPath)
}
发现路径最好的方法是通过代码实现。
使用Swift,只需将下面的代码粘贴到您的AppDelegate.swift中的application函数内:
let paths = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)
let documentsPath = paths.first as String
println(documentsPath)