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 模拟器的文档目录路径在哪里?
在我的电脑上,路径是:
~/Library/Developer/CoreSimulator/Devices/1A8DF360-B0A6-4815-95F3-68A6AB0BCC78/data/Container/Data/Application/
注意: 对于你的计算机来说,那些长的ID(如UDID)可能是不同的。
NSLog
代码,运行您的项目并跟随路径。这将使您更容易访问文档,而不是在“〜/库/开发者/CoreSimulator/Devices/”中随机搜索。
Objective-CNSLog(@"%@",[[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject]);
Swift
如果您正在使用Swift 1.2,请使用以下代码,该代码仅在使用模拟器时才会在开发中输出,因为使用了#if
#endif
块:
#if arch(i386) || arch(x86_64)
let documentsPath = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] as! NSString
NSLog("Document Path: %@", documentsPath)
#endif
从"/Users/ankur/Library/Developer/CoreSimulator/Devices/7BA821..."复制路径,进入"Finder"然后点击"前往文件夹"或按command + shift + g,粘贴您的路径,让Mac带您到文档目录 :)
在 AppDelegate 的 didFinishLaunchingWithOptions 方法中写入以下代码:
Objective C
#if TARGET_IPHONE_SIMULATOR
// where are you?
NSLog(@"Documents Directory: %@", [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject]);
#endif
Swift 2.Xif let documentsPath = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask).first?.path {
print("Documents Directory: " + documentsPath)
}
Swift 3.X
#if arch(i386) || arch(x86_64)
if let documentsPath = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first?.path {
print("Documents Directory: \(documentsPath)")
}
#endif
Swift 4.2
#if targetEnvironment(simulator)
if let documentsPath = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first?.path {
print("Documents Directory: \(documentsPath)")
}
#endif
输出
/Users/mitul_marsonia/Library/Developer/CoreSimulator/Devices/E701C1E9-FCED-4428-A36F-17B32D32918A/data/Containers/Data/Application/25174F64-7130-4B91-BC41-AC74257CCC6E/Documents
从 "/Users/mitul_marsonia/Library/Developer/CoreSimulator/Devices/E701C1E9-FCED-4428-A36F-17B32D32918A..."复制你的路径,打开 "Finder" 然后执行 "前往文件夹" 或者使用快捷键 command + shift + g 并粘贴你的路径,让Mac带你进入到你的文档目录。
虽然有许多答案,但没有一个提供了iOS 8.3模拟器文件夹结构发生变化的理解,并且没有提供快速查找应用程序数据(文档文件夹)的方法。
自从iOS 8以来,应用程序的数据存储文件夹与应用程序的可执行文件分离,而iOS 7及以下版本具有相同的文件夹结构,唯一的区别在于所有模拟器(不同类型和版本)现在都在一个大文件夹中。
因此,iOS 8、7、6模拟器的路径如下:
~/Library/Developer/CoreSimulator/Devices
每个模拟器现在都包含在一个名为唯一标识符的文件夹中,在每次模拟器重置时,标识符都会更改。
您可以通过转到Xcode > 窗口 > 设备
(记住标识符的前3或4个字符就足够了)找到每个设备和模拟器的标识符
。
要找到您已安装您的应用程序的模拟器,请查看您的运行方案 > 设备
(屏幕2)。
现在,在确定您的模拟器之后,取决于其版本,文件夹结构会有所不同:
在iOS 8上,应用程序的可执行文件和数据文件夹位于不同的文件夹中:
可执行文件:
~/Library/Developer/CoreSimulator/Devices/[simID]/data/Containers/Bundle/Application/[appID]
数据文件夹:
~/Library/Developer/CoreSimulator/Devices/[simID]/data/Containers/Data/Application/[appID]/
文档文件夹:
~/Library/Developer/CoreSimulator/Devices/[simID]/data/Containers/Data/Application/[appID]/Documents
在iOS 7及以下版本,文件夹结构与之前相同,只需记住现在每个模拟器都在同一个文件夹中(见上文)。
我推荐一款名为SimPholders的好用实用工具应用程序,可以帮助您在开发iOS应用程序时轻松查找文件和文件夹。 它有一个新版本可以与新的模拟器SimPholders2配合使用,并可在simpholders.com找到。
如果您的应用程序使用CoreData,一个巧妙的技巧是使用终端搜索sqlite文件的名称。
find ~ -name my_app_db_name.sqlite
结果将列出运行您的应用程序的任何模拟器的完整文件路径。
我真希望苹果公司能够在iOS模拟器文件菜单中添加一个按钮,比如“在Finder中显示文档文件夹”。
我们需要查看路径~/Library/Developer/CoreSimulator/Devices/是正确的。
但我看到的问题是,每次运行应用程序时路径都会发生变化。该路径包含另一组长ID,在Application字符串之后,并且每次运行应用程序时都会更改。
这基本上意味着当下次运行应用程序时,我的应用程序将不具有任何缓存数据。
使用终端和 simctl:
xcrun simctl get_app_container booted my.app.identifier data
.zprofile
中添加了一个函数:openDocuments() { open -R "$(xcrun simctl get_app_container booted my.app.identifier data)/Documents" }
- Anton Plebanovichif let documentsPath = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first?.path {
print(documentsPath) // "var/folder/.../documents\n" copy the full path
}
打开Finder,按下Command-Shift-G(或在菜单栏下选择Go > Go to Folder...),将完整路径“var/folder/.../documents”粘贴到输入框中,然后点击前往。