iOS 8 Beta模拟器的文档目录路径

Fir*_*ist 87 ios ios-simulator ios8

在iOS 7中,可以在以下位置找到iOS模拟器的文档目录:

/Users/Sabo/Library/Application Support/iPhone Simulator/
Run Code Online (Sandbox Code Playgroud)

但是,在iOS 8 Beta Simulator中,我在上面的目录中找不到iOS 8的相应目录.

iOS 8模拟器的文档目录路径在哪里?

在此输入图像描述

hol*_*lex 152

在我的电脑上,路径是:

~/Library/Developer/CoreSimulator/Devices/1A8DF360-B0A6-4815-95F3-68A6AB0BCC78/data/Container/Data/Application/
Run Code Online (Sandbox Code Playgroud)

注意:您的计算机上可能有那些长ID​​(即UDID)不同.

  • 不,这是不正确的.ObjC项目和Swift项目之间没有区别.那些是UDID(唯一设备标识符),你可以通过运行'xcrun simctl list'看到你的 (12认同)
  • Holex,我说你的陈述是错误的,而不是设计不正确(请注意,我实际上是Apple设计CoreSimulator的那个人,所以我可能是第一个纠正那里的人,我认为是错误).UDID对应于单独的设备.您的swift和objc项目使用不同UDID的唯一原因是您将项目部署到不同的模拟器设备(例如:一个部署到iPhone 5s,另一个部署到iPhone 6). (7认同)

Ank*_*kur 72

NSLog在"AppDelegate"中的某个代码下面,运行你的项目并按照路径行进.这对于您来说很方便,而不是在"〜/ Library/Developer/CoreSimulator/Devices /"中随机搜索

Objective-C的

NSLog(@"%@",[[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject]);
Run Code Online (Sandbox Code Playgroud)

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
Run Code Online (Sandbox Code Playgroud)

复制你的路径从"/ Users/ankur/Library/Developer/CoreSimulator/Devices/7BA821 ..."转到" Finder ",然后" 转到文件夹 "或command+ shift+ g并粘贴你的路径,让mac带你到你的文件目录:)


Mit*_*iya 38

只需在AppDelegate中编写以下代码- > didFinishLaunchingWithOptions Objective C.

#if TARGET_IPHONE_SIMULATOR 
// where are you? 
NSLog(@"Documents Directory: %@", [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject]); 
#endif 
Run Code Online (Sandbox Code Playgroud)


Swift 2.X

if let documentsPath = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask).first?.path {
    print("Documents Directory: " + documentsPath)   
}
Run Code Online (Sandbox Code Playgroud)

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
Run Code Online (Sandbox Code Playgroud)

Swift 4.2

#if targetEnvironment(simulator)
    if let documentsPath = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first?.path {
        print("Documents Directory: \(documentsPath)")
    }
#endif
Run Code Online (Sandbox Code Playgroud)

输出
/用户/ 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"然后"转到文件夹"或命令+ shift + g和粘贴你的路径,让mac带你到你的文件目录


JDi*_*ble 16

我推荐一个名为SimPholders的漂亮的实用程序应用程序,可以在开发iOS应用程序时轻松找到文件和文件夹.它有一个新版本可以使用名为SimPholders2的新模拟器.它可以在simpholders.com找到


Raz*_*van 14

尽管这里有很多答案,但它们都没有提供对iOS 8.3模拟器的文件夹结构如何变化的理解,也没有提供快速查找应用程序数据(文档文件夹)的方法.

从iOS 8开始,应用程序的数据存储文件夹与应用程序的可执行文件分开,而iOS 7及更低版本具有相同的文件夹结构,唯一的区别是所有模拟器(不同类型和版本)都是现在在一个大文件夹中.

因此,iOS 8,7,6模拟器的路径如下:

~/Library/Developer/CoreSimulator/Devices
Run Code Online (Sandbox Code Playgroud)

每个模拟器现在都包含在一个以唯一标识符命名的文件夹中,该标识符在模拟器的每次重置时都会更改.

您可以Identifier通过转到Xcode > Window > Devices(标识符的前3个或4个字符足以记住)找到每个设备和模拟器.

要查找已安装应用程序的应用程序,请查看您的Run scheme > devices(屏幕2).

屏幕1

屏幕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及更低版本下,文件夹结构与以前相同,只记得现在每个模拟器都在同一个文件夹中(见上文).


Dis*_*Dev 13

如果您的应用程序使用CoreData,一个很好的技巧是使用终端搜索sqlite文件的名称.

find ~ -name my_app_db_name.sqlite
Run Code Online (Sandbox Code Playgroud)

结果将列出运行应用程序的任何模拟器的完整文件路径.

我真的希望Apple只是在iOS Simulator文件菜单中添加一个按钮,如"在Finder中显示文档文件夹".

  • 这似乎是找到这个的非常有趣的方式.搜索整个主目录? (2认同)

Dee*_*G M 11

我们需要查看路径〜/ Library/Developer/CoreSimulator/Devices /是正确的.

但我看到的问题是每次运行应用程序时路径都在不断变化.该路径在Application字符串后面包含另一组长ID,并且每次运行应用程序时都会不断更改.这基本上意味着我的应用程序下次运行时不会有任何缓存数据.

  • 运行应用程序时,路径不会随时更改.您的库中每个设备有一个路径.运行'xcrun simctl list'以查看设备列表及其UDID,以查看您应该考虑的子目录. (5认同)

Ula*_*mir 9

使用终端 && simctl:

xcrun simctl get_app_container booted my.app.identifier data
Run Code Online (Sandbox Code Playgroud)

  • 我发现这是最有用的答案。打印当前运行模拟器的给定应用程序数据容器(包括文档)的目录。要直接在 Finder 中打开目录:`open ``xcrun simctl get_app_container booted my.app.identifier data``` (2认同)

Jer*_*oia 7

随着在Xcode 6.0中采用CoreSimulator,数据目录是按设备而不是按版本.数据目录是〜/ Library/Developer/CoreSimulator/Devices //数据,其中可以从'xcrun simctl list'确定

请注意,如果您不打算回滚到Xcode 5.x或更早版本,可以安全地删除〜/ Library/Application Support/iPhone Simulator和〜/ Library/Logs/iOS Simulator.


Bou*_*uke 7

对于iOS 9.2和Xcode 7.2,以下脚本将打开上次使用的模拟器上最后安装的应用程序的Documents文件夹;

cd ~/Library/Developer/CoreSimulator/Devices/
cd `ls -t | head -n 1`/data/Containers/Data/Application 
cd `ls -t | head -n 1`/Documents
open .
Run Code Online (Sandbox Code Playgroud)

要创建一个简单的可运行脚本,请将其放入带有"运行Shell脚本"的Automator应用程序中:

在Automator应用程序中运行Shell脚本


Leo*_*bus 5

更新:Xcode 7.2•Swift 2.1.1

if let documentsPath = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask).first?.path {
    print(documentsPath)   // "var/folder/.../documents\n" copy the full path
}
Run Code Online (Sandbox Code Playgroud)

转到你的Finder按下命令shift-g(或菜单栏下的Go> Go to Folder ...)并在那里粘贴完整路径"var/folder /.../ documents"并按go.