是否可以在调试时查看 iOS 应用程序沙箱中文件的内容?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7405790/
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-30 21:30:08  来源:igfitidea点击:

Is it possible to view the contents of files in the iOS Application sandbox while debugging?

iosxcodedebuggingloggingxcode4

提问by Will Pragnell

I'd like to check the contents of an XML file at a specific point of execution while debugging in Xcode. Is it possible to view the contents of the file, either through the Organizer (I'm debugging using actual hardware devices, not the simulator), or by typing in some sort of command into the output/console?

我想在 Xcode 中调试时在特定执行点检查 XML 文件的内容。是否可以通过管理器(我正在使用实际硬件设备而不是模拟器进行调试)或通过在输出/控制台中输入某种命令来查看文件的内容?

I am using Xcode 4.

我正在使用 Xcode 4。

回答by pstoppani

Simply open the organiser and click the 'Download' button at the bottom, then right click on the xcappdata file and select Show Package Contents.

只需打开管理器并单击底部的“下载”按钮,然后右键单击 xcappdata 文件并选择显示包内容。

回答by James Perih

Updated answer for Xcode 6:

Xcode 6 的更新答案:

The Devices tab now has it's own window (Window -> Devices). Find your Device, then your App. There is no 'download' button (unless the log window is visible... then the Download icon there actually saves the Log).

设备选项卡现在有它自己的窗口(窗口 -> 设备)。找到您的设备,然后找到您的应用程序。没有“下载”按钮(除非日志窗口可见......然后那里的下载图标实际上保存了日志)。

If you DOUBLE-CLICK on your app, a new window will become visible that shows a read-only, non-interactive representation of that app's sandbox.

如果您双击您的应用程序,则会出现一个新窗口,显示该应用程序沙箱的只读、非交互式表示。

To download the app container, select an app, click the "Gear" and "Download Container." It'll take a bit of a while, during which time there is no indication of the progress; but a Finder window will appear, showing with your .xcappdata file. You can also "Replace Container" which looks cool and exciting.

要下载应用程序容器,请选择一个应用程序,单击“齿轮”和“下载容器”。需要一点时间,在此期间没有任何进度指示;但会出现一个 Finder 窗口,显示您的 .xcappdata 文件。您还可以“更换容器”,看起来很酷很刺激。

回答by SVD

You could enable file sharing (set the UIFileSharingEnabled flag in info.plist) and store the file where it can be accessed via iTunes (i.e. in the Documents folder).

您可以启用文件共享(在 info.plist 中设置 UIFileSharingEnabled 标志)并将文件存储在可以通过 iTunes 访问的位置(即在 Documents 文件夹中)。

回答by Will Pragnell

I have just discovered that you can in fact save the entire contents of the sandbox to disk at any time. Simply open the organiser and click the 'Download' button at the bottom. This saves the sandbox to disk as a .xcappdata file. I'm not sure how to open this as it is, but I have found that if you change the file extension to .xml, you can browse it using finder just like a normal directory.

我刚刚发现您实际上可以随时将沙箱的全部内容保存到磁盘。只需打开管理器并单击底部的“下载”按钮即可。这会将沙箱作为 .xcappdata 文件保存到磁盘。我不确定如何按原样打开它,但我发现如果将文件扩展名更改为 .xml,则可以像普通目录一样使用 finder 浏览它。

It's a shame you can't download single files if required and that the whole process is a little cumbersome, but it does allow me to achieve what I wanted in the end.

很遗憾,如果需要,您无法下载单个文件,整个过程有点麻烦,但它确实让我最终实现了我想要的。

回答by Lio

You can always set a breakpoint and then, in the console, print the contents of the object you want to examine using 'po'. Example: gdb> po [NSDictionary dictionaryWithContentsOfFile: filePath];.

您始终可以设置断点,然后在控制台中使用“po”打印要检查的对象的内容。示例:gdb> po [NSDictionary dictionaryWithContentsOfFile: filePath];。