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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25198840/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 01:45:25  来源:igfitidea点击:

Document Directory Path of iOS 8 Beta Simulator

iosios8ios-simulator

提问by Fire Fist

In iOS 7, the document directory of the iOS simulators can be found in:

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

/Users/Sabo/Library/Application Support/iPhone Simulator/

However, in iOS 8 Beta Simulator, I can't find the corresponding directory for iOS 8in the directory above.

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

Where's the document directory path for the iOS 8 Simulator?

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

enter image description here

在此处输入图片说明

回答by holex

on my computer, the path is:

在我的电脑上,路径是:

~/Library/Developer/CoreSimulator/Devices/1A8DF360-B0A6-4815-95F3-68A6AB0BCC78/data/Container/Data/Application/


NOTE:probably those long IDs (i.e UDIDs) are different on your computer.

注意:可能那些长 ID(即 UDID)在您的计算机上是不同的。

回答by Ankur

NSLogbelow code somewhere in "AppDelegate", run your project and follow the path. This will be easy for you to get to the documents rather than searching randomly inside "~/Library/Developer/CoreSimulator/Devices/"

NSLog在“AppDelegate”中某处的代码下方,运行您的项目并按照路径进行操作。这对您来说很容易找到文档,而不是在“~/Library/Developer/CoreSimulator/Devices/”中随机搜索

Objective-C

目标-C

NSLog(@"%@",[[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject]);

Swift
If you are using Swift 1.2, use the code below which will only output in development when using the Simulator because of the #if#endifblock:

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


Copy your path from "/Users/ankur/Library/Developer/CoreSimulator/Devices/7BA821..." go to "Finder" and then "Go to Folder" or command+ shift+ gand paste your path, let the mac take you to your documents directory :)

从复制你的路径“/用户/ ANKUR /库/开发商/ CoreSimulator /设备/ 7BA821 ......”进入“查找”,然后“前往文件夹”或command+ shift+g粘贴您的路径,让MAC带你到你文件目录:)

回答by Mitul Marsoniya

Just writebellow code in AppDelegate-> didFinishLaunchingWithOptions
Objective C

只需在AppDelegate-> didFinishLaunchingWithOptions Objective C 中编写波纹管代码

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


Swift 2.X


斯威夫特 2.X

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

Swift 3.X

斯威夫特 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

斯威夫特 4.2

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

Output
/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/data/Containers/Data/Application/25174F64-7130-4B91-BC457-AC7642

Copy your path from"/Users/mitul_marsonia/Library/Developer/CoreSimulator/Devices/E701C1E9-FCED-4428-A36F-17B32D32918A..." go to "Finder" and then "Go to Folder" or command + shift + g and paste your path, let the mac take you to your documents directory

“/Users/mitul_marsonia/Library/Developer/CoreSimulator/Devices/E701C1E9-FCED-4428-A36F-17B32D32918A...”复制您的路径,然后转到“Finder”,然后“转到文件夹”或命令+ shift + g 和粘贴您的路径,让 mac 带您到您的文档目录

回答by JDibble

I recommend a nice utility app called SimPholders that makes it easy to find the files and folders while developing your iOS app. It has a new version to work with the new simulators called SimPholders2. It can be found at simpholders.com

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

回答by Razvan

Despite the fact that here are many answers, none of them provides an understanding of how the folder structure of the iOS 8.3 simulators have changed and are not providing a quick way to find the App's Data (Documents folder).

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

Since iOS 8 the Data storage folder(s) of an App are separate from the App's executable files while the iOS 7 and below are having the same folder structure, the only difference being the fact that all the simulators (different types and versions) are now in one, big folder.

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

So, the path to an iOS 8,7,6 simulator is the following:

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

~/Library/Developer/CoreSimulator/Devices

Every simulator is now contained in a folder named with an unique identifier which changes at every reset of a simulator.

每个模拟器现在都包含在一个以唯一标识符命名的文件夹中,该标识符在模拟器每次重置时都会发生变化。

You can find the Identifierfor each of your devices & simulators by going to Xcode > Window > Devices(the first 3 or 4 characters of the identifier are more than enough to remember).

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

To find the one on which you have installed your app(s) on, take a look at your Run scheme > devices(screen 2).

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

screen 1

屏幕 1

screen 2

屏幕 2

Now, after you identify your simulator, depending on its version the folder structure is very different:

现在,在您确定您的模拟器后,根据其版本,文件夹结构非常不同:

On iOS 8the executable and the data folder of an app are in different folders:

在 iOS 8上,应用程序的可执行文件和数据文件夹位于不同的文件夹中:

Executable: ~/Library/Developer/CoreSimulator/Devices/[simID]/data/Containers/Bundle/Application/[appID]

可执行文件~/Library/Developer/CoreSimulator/Devices/[simID]/data/Containers/Bundle/Application/[appID]

Data Folder: ~/Library/Developer/CoreSimulator/Devices/[simID]/data/Containers/Data/Application/[appID]/

数据文件夹~/Library/Developer/CoreSimulator/Devices/[simID]/data/Containers/Data/Application/[appID]/

Documents Folder: ~/Library/Developer/CoreSimulator/Devices/[simID]/data/Containers/Data/Application/[appID]/Documents

文件文件夹~/Library/Developer/CoreSimulator/Devices/[simID]/data/Containers/Data/Application/[appID]/Documents

On iOS 7and below the folder structure is the same as before only remember that now every simulator is in the same folder (see above).

iOS 7及以下的文件夹结构和以前一样,只记得现在每个模拟器都在同一个文件夹中(见上文)。

回答by DiscDev

If your app uses CoreData, a nifty trick is to search for the name of the sqlite file using terminal.

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

find ~ -name my_app_db_name.sqlite

The results will list the full file paths to any simulators that have run your app.

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

I really wish Apple would just add a button to the iOS Simulator file menu like "Reveal Documents folder in Finder".

我真的希望 Apple 只需在 iOS 模拟器文件菜单中添加一个按钮,例如“在 Finder 中显示文档文件夹”。

回答by Deepak G M

It is correct that we need to look into the path ~/Library/Developer/CoreSimulator/Devices/.

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

But the issue I am seeing is that the path keeps changing every time I run the app. The path contains another set of long IDs after the Application string and that keeps changing every time I run the app. This basically means that my app will not have any cached data when it runs the next time.

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

回答by Jeremy Huddleston Sequoia

With the adoption of CoreSimulator in Xcode 6.0, the data directories are per-device rather than per-version. The data directory is ~/Library/Developer/CoreSimulator/Devices//data where can be determined from 'xcrun simctl list'

随着 Xcode 6.0 中 CoreSimulator 的采用,数据目录是每个设备而不是每个版本。数据目录是 ~/Library/Developer/CoreSimulator/Devices//data 其中可以从'xcrun simctl list'确定

Note that you can safely delete ~/Library/Application Support/iPhone Simulator and ~/Library/Logs/iOS Simulator if you don't plan on needing to roll back to Xcode 5.x or earlier.

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

回答by Bouke

With iOS 9.2 and Xcode 7.2, the following script will open the Documents folder of the last installed application on the last used simulator;

对于 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 .

To create an easy runnable script, put it in an Automator Application with "Run Shell Script":

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

Run Shell Script inside Automator Application

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

回答by Leo Dabus

update: Xcode 7.2 ? Swift 2.1.1

更新:Xcode 7.2?斯威夫特 2.1.1

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

Go to your Finder press command-shift-g (or Go > Go to Folder... under the menu bar) and paste that full path "var/folder/.../documents" there and press go.

转到您的 Finder,按 command-shift-g(或菜单栏下的 Go > Go to Folder...)并粘贴完整路径“var/folder/.../documents”,然后按 go。