Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Including application data in iOS simulator

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

like image 212
AlexMath Avatar asked Dec 06 '17 22:12

AlexMath


People also ask

How do I put apps on my iPhone simulator?

Install Apps on Simulators Go to Apps > Install Application. Find and open the app you want to install from your Mac. The app appears in the list of installed apps on the right side of the iOS Gateway window.

Where does the iPhone simulator store its data?

type: ~/Library/Application Support/iPhone Simulator.

Can you run an IPA file on a simulator?

Just like an APK (Android Application Package) file can be installed on Android devices, an IPA file can be used for testing iOS applications. You can even push it to the app stores to publish your app. You can think of an IPA file like a simple ZIP file.


2 Answers

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.

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

like image 62
russbishop Avatar answered Oct 17 '22 23:10

russbishop


I've just figured it out that, as a workaround at least for Xcode 9.2/iOS 11.2 simulator, you can set (HOME/CFFIXED_USER_HOME) (I'm not sure whether of those actually works) environment variables in launch arguments to a path to .xcappdata/AppData, like shown below (I used SRCROOT relative path just for illustration of possibilities - it works with any other kind of path like absolute ones and etc). Beware that the changes in the app data will be reflected right in that folder, so if you don't want that, it makes sense to point it to the copy.

Environment for .xcappdata

like image 31
Grigory Entin Avatar answered Oct 17 '22 23:10

Grigory Entin