在iOS模拟器中包含应用程序数据 [英] Including application data in iOS simulator

查看:77
本文介绍了在iOS模拟器中包含应用程序数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,可将加速度计数据记录和存储为核心数据托管对象.我想在模拟器中包含一些示例保存的录音,以在不同平台上测试应用程序,因为模拟器无法从加速度计进行录制.我已在构建方案中成功包含* .xcappdata文件,该文件可在设备上使用,但模拟器提取却变空了.

I have an app that records and stores accelerometer data as core data managed objects. I would like to include some sample saved recordings in the simulator to test the app on different platforms, since the simulator cannot record from the accelerometer. I have successfully included *.xcappdata files in the build scheme and it works on devices, but simulator fetches come back empty.

Apple文档似乎可以表示可以在模拟器中包含应用程序数据,但我尚未使其正常工作.我已经测试过,包括从一台设备保存到另一台设备上的数据,并且工作正常.我没有收到任何错误消息,只是一个空的获取.

Apple documentation seems to indicate that including app data in the simulator is possible but I have not gotten it to work. I have tested including data saved from one device on another device and that works fine. I am getting no error message, just an empty fetch.

我知道我可以在应用程序中以文本文件的形式包含数据,在启动时对其进行读取和格式化,并将其保存为托管对象,但这会在项目中创建大量的附录代码和文件,我宁愿更干净地工作.

I know I could include data in the form of text files in the app, read and format them upon launch, and save them as managed objects, but it would create a bunch of appendix code and files in the project, and I would rather work more cleanly.

推荐答案

您可以通过运行 xcrun simctl get_app_container< device>来找到应用程序的数据容器路径.<捆绑包标识符>终端窗口中的数据.设备可以是名称(带引号)或UDID(请参见 xcrun simctl列表).为此,相关的模拟器必须正在运行,并在其上安装了该应用程序的版本.

You can find your application's data container path by running xcrun simctl get_app_container <device> <bundle identifier> data in a Terminal window. Device can be the name (quoted) or the UDID (see xcrun simctl list). For this to work, the relevant simulator will have to be running, and have a version of the app installed on it.

右键单击.appdata文件以显示软件包的内容.将您从AppData/*中的文件夹"中获得的核心数据文件复制到类似目录中,然后在模拟器中启动您的应用程序.

Right-click on the .appdata file to show the contents of package. Copy the core data files you got from Folders in AppData/* into the analogous directory then start your app in the Simulator.

Xcode当前没有像在物理设备中那样具有在模拟器中管理容器的GUI.如果您不介意,请通过 https://bugreport.apple.com/提出增强请求在设备和设备中模拟器窗口.

Xcode does not currently have a GUI to manage containers in the Simulator like it does for physical devices. If you don't mind please file an enhancement request at https://bugreport.apple.com/ requesting this in the Devices & Simulators window.

这篇关于在iOS模拟器中包含应用程序数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆