ios 有没有办法在iOS模拟器上查看文件系统?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6480607/
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
Is there any way to see the file system on the iOS simulator?
提问by Chris Williams
Is there any way to browse the file system of a currently running or just killed iOS simulator? I'd settle for being able to see a specific app's files if there's a way to do that.
有没有办法浏览当前正在运行或刚刚杀死的 iOS 模拟器的文件系统?如果有办法做到这一点,我会满足于能够查看特定应用程序的文件。
Note that I don't want to do this programatically. I want to see/open the files in the Finder.
请注意,我不想以编程方式执行此操作。我想在 Finder 中查看/打开文件。
回答by Kendall Helmstetter Gelner
UPDATE:Since iOS 8:
更新:从 iOS 8 开始:
~/Library/Developer/CoreSimulator/Devices
~/库/开发人员/CoreSimulator/设备
The location used to be:
曾经的位置是:
~/Library/Application Support/iPhone Simulator
~/库/应用程序支持/iPhone 模拟器
It had directories for all models of simulators (4.0, 4.1, 5.0, etc) you have ever run, go to the one you are running from in Xcode.
它有您曾经运行过的所有模拟器模型(4.0、4.1、5.0 等)的目录,请转到您在 Xcode 中运行的那个。
Once in a folder, go to Applications, choose the Finder option that shows date for files, and sort by date. Your application will be the most recent since it just changed the directory...
进入文件夹后,转到应用程序,选择显示文件日期的 Finder 选项,然后按日期排序。您的应用程序将是最新的,因为它只是更改了目录...
Inside the directory is everything related to your application. You can even drop files in there between runs, to revert back to a stored database in a known state for example...
目录内是与您的应用程序相关的所有内容。您甚至可以在两次运行之间将文件放入其中,以恢复到处于已知状态的存储数据库,例如...
I go there often enough I keep the iPhone Simulator directory in my Finder sidebar.
我经常去那里,我将 iPhone Simulator 目录保存在我的 Finder 侧边栏中。
Note that with iOS8, the simulator folders are in a totally different directory - really split across a few directories, with folder names for application specific files that change each time you run your app.
请注意,在 iOS8 中,模拟器文件夹位于完全不同的目录中 - 实际上分为几个目录,应用程序特定文件的文件夹名称在每次运行应用程序时都会更改。
回答by Mohsen
iOS 8
iOS 8
Devices
设备
~/Library/Developer/CoreSimulator/Devices
Applications
应用
~/Library/Developer/CoreSimulator/Devices/{{Device Code}}/data/Containers/Bundle/
回答by vikingosegundo
Open the program "Activity Monitor", search for your App (just the apps name, not the simulator), click "Informations" and open "Open files and ports". Copy the second entry (something like /Users/me/Library/Application Support/iPhone Simulator/4.2/Applications/B97A9504-0FA5-4826-BB6D-A2335A676459/VSGradientView.app/YourApp
). This is the running app, while <...>/B97A9504-0FA5-4826-BB6D-A2335A676459/VSGradientView.app/
is the bundle, and <...>/B97A9504-0FA5-4826-BB6D-A2335A676459/*
the sand-boxed folder.
打开程序“活动监视器”,搜索您的应用程序(仅应用程序名称,而不是模拟器),单击“信息”并打开“打开文件和端口”。复制第二个条目(类似于/Users/me/Library/Application Support/iPhone Simulator/4.2/Applications/B97A9504-0FA5-4826-BB6D-A2335A676459/VSGradientView.app/YourApp
)。这是正在运行的应用程序,<...>/B97A9504-0FA5-4826-BB6D-A2335A676459/VSGradientView.app/
而是捆绑包和<...>/B97A9504-0FA5-4826-BB6D-A2335A676459/*
沙盒文件夹。
If you pass this as open "/Users/me/Library/Application Support/iPhone Simulator/4.2/Applications/B97A9504-0FA5-4826-BB6D-A2335A676459/"
to the terminal, the folder will open in Finder.
如果您将其传递open "/Users/me/Library/Application Support/iPhone Simulator/4.2/Applications/B97A9504-0FA5-4826-BB6D-A2335A676459/"
给终端,该文件夹将在 Finder 中打开。
Sounds complicated but isn't.
听起来很复杂,其实不然。
回答by Tung Fam
Easy. Fast. Xcode 10+.
简单。快速地。Xcode 10+。
- Use
print(NSHomeDirectory())
and copythe path. - Open Finderapp and press
Shift+Cmd+G
- Pastethe copied path and press GO
- 使用
print(NSHomeDirectory())
并复制路径。 - 打开Finder应用程序并按
Shift+Cmd+G
- 粘贴复制的路径并按GO
Alternative for 1. is to catch a breakpoint and do po NSHomeDirectory()
in console.
1. 的替代方法是捕获断点并po NSHomeDirectory()
在控制台中执行。
回答by Vasily Bodnarchuk
based on zseroanswer
基于zsero答案
Details
细节
macOS 10.13.1
macOS 10.13.1
Solution 1
解决方案1
Run the following line in the terminal
在终端中运行以下行
Template
模板
open `xcrun simctl get_app_container booted BUNDLEID_OF_YOUR_APP data` -a Finder
Full Sample
完整样本
open `xcrun simctl get_app_container booted com.Test data` -a
BUNDLEID_OF_YOUR_APP ???
BUNDLEID_OF_YOUR_APP ???
BUNDLEID_OF_YOUR_APP = "Bundle Identifier"
BUNDLEID_OF_YOUR_APP = "捆绑标识符"
Features of the solution 1
解决方案的特点 1
- open file to get app simulator directory
- 打开文件以获取应用程序模拟器目录
Solution 2
解决方案2
Create a bash scrip with a name of your app and code:
使用您的应用程序名称和代码创建一个 bash 脚本:
script_file_name = `basename "xcrun simctl get_app_container booted my.app.id data
"`
open `xcrun simctl get_app_container booted $script_file_name data`
Features of the solution 2
解决方案的特点2
- open file to get app simulator directory
- rename file to get another app simulator directory
- 打开文件以获取应用程序模拟器目录
- 重命名文件以获取另一个应用程序模拟器目录
Result
结果
回答by deepflame
There is a nifty app that also supports the XCode 6 simulator.
有一个漂亮的应用程序也支持 XCode 6 模拟器。
https://github.com/somegeekintn/SimDirs
https://github.com/somegeekintn/SimDirs
It is awesome, use it!
厉害了,用起来!
回答by hyperknot
If you want to automate getting the location or use that folder in scripting, you can get the precise location from a runningsimulator with the following command:
如果要自动获取位置或在脚本中使用该文件夹,可以使用以下命令从正在运行的模拟器中获取精确位置:
#!/bin/bash
APPID=
if OUTPUT=`xcrun simctl get_app_container booted $APPID data` ; then
open $OUTPUT
else
echo "$APPID not found!"
fi 2>/dev/null
回答by lindon fox
Old post, but I think it is worth mentioning SimPholdersto find your Simulator files. It is a menu bar item that tracks your simulator apps and lets you go directly to their folders and content. It's super awesome.
旧的文章,但我认为这是值得一提的SimPholders找到你的模拟器文件。它是跟踪你的模拟器的应用程序,让你直接去他们的文件夹和内容的菜单栏项目。太棒了。
(original answer here: https://stackoverflow.com/a/26557165/377384)
(原答案在这里:https: //stackoverflow.com/a/26557165/377384)
回答by Martin
Based on @zsero answer, I made a short bash
script which directly opens the simulator folder of your application id. Very handy!
根据@zsero 的回答,我制作了一个简短的bash
脚本,可以直接打开您的应用程序 ID 的模拟器文件夹。非常便利!
openappfolder.sh
打开应用程序文件夹.sh
openappfolder.sh com.bundle.id
Then just
那么就
#if targetEnvironment(simulator)
print("::::: SIMULATOR :::::")
if let documentsPath = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first?.path {
print("App Documents Directory:\n\(documentsPath)\n")
}
#endif
回答by l --marc l
For Swift 4.2 and higher, place something like the following code:
对于 Swift 4.2 及更高版本,放置如下代码:
func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
// ...
return true
}
... in a source code location such as:
...在源代码位置,例如:
##代码##Use the resulting path with cd
or open
on the terminal command line. Or, paste the path in the shift-cmd-G
"Go To Folder…" Finder prompt.
在终端命令行上使用cd
或生成的路径open
。或者,将路径粘贴到shift-cmd-G
“转到文件夹...”Finder 提示中。
Related answer which includes older language versions: Document Directory Path of iOS 8 Beta Simulator
包含旧语言版本的相关答案:iOS 8 Beta Simulator 的文档目录路径