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.
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.
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.
Related
Problem: I have a friend's iPhone that I am working with who had some 3rd party Canon app that created an overwhelming amount of "Albums" (5848499495 of them to be exact!!).
Refer to this video
Obviously, this definitely shouldn't happen and we're trying to see what's the best way to delete all of them.
I was thinking of accessing the files via SSH on the iPhone to see if these "Albums" are represented as directories somewhere in the iPhone's file structure and run some type of shell script to batch remove files as we would on our Macs but I realize that this will require some jailbreaking which we're trying to avoid doing if possible. But will consider it if it's easier to do it that way.
I also tried to see if there were Command Line tools for the iPhone to directly access the root folder to see if we could find the directory but I realize that there are permission issues associated with accessing the iPhone's files without jailbreaking.
These albums are stored locally on the phone, and it's not in iCloud. We tried to see if these folders show up on Mac's photo app after syncing but because they are empty folders, it doesn't show on the app.
Note: we're on a Mac, and the model is an iPhone X running the latest iOS 14.
I'm all out of ideas and any help would be wonderful.
Thanks!
I'm trying to save files generated while running unit tests that are later loaded through the same tests on a different simulator/at a different time. I can't use the NSDocumentsDirectory because it changes every time I run the app on the same simulator. What shared directory can I write to or what path can I write to where the files can be loaded between different test runs?
Notes:
The recorded data is being recorded as the tests run. I'm recording http traffic and writting it to files to be loaded later.
I'm running all the tests on the same simulator, so if the directory isn't accessible between simulators that's fine. I want it to be accessible by the same simulator on different runs.
When an iOS app writes to its documents directory on the iPhone simulator (NSDocumentDirectory), the data remains available to subsequent runs. Even if the app gets rebuilt/reinstalled, the data will remain with the app, but in the new NSDocumentDirectory. Even though the root app directory is different, the documents are automatically moved to the new NSDocumentDirectory.
So it just works, so long as its on the same simulator, in the same way it does if it is on the same device. You don't need to do anything.
I found that the trick when using the Mac OS X Finder or a terminal (for me) was to stop looking in the same absolute directory all the time, and get the app to log whatever the current documents directory is, and then check for the existence of the documents there in that new directory. I found that the system always moved documents there for me every time I rebuilt/reinstalled the app.
It appears to be much the same behaviour as when updating an app on a real device from the App Store, as far as I can tell. I guess it installs the new app, then moves all data from the old app to the new app, then deletes the old app.
Simulators are like separate devices: they can't share files, and neither can new installs (from a rebuild) of your app.1 I think you'll have to generate the files, and then find them manually in the simulated app container.
Then you can add the files to your test target in the "Copy bundle resources" build phase, then access them via NSBundle. The main bundle will still be the application even when testing, but you can find the right bundle with +bundleForClass: and a class that's only present in your test target.
1Son of a Beach's answer points out that this is wrong.
I am working on a library with a very verbose logger module that, on iOS, writes xml logs to NSDocumentDirectory in a consistent file tree. I want to come up with a way for the user of this library to easily access these logs.
I know it is simple to programatically retrieve files from this directory, but is it possible to access this directory on an iOS physical device in any way from outside Xcode to retrieve these logs? I feel like I have seen it somewhere before, something in the manner of extracting the .ipa file and going into the package contents, but I could be wrong.
---------------------------------------------------------EDIT------------------------------------------------------------------
This (Browse the files created on a device by the IOS application I'm developing, on workstation?) is how to do it with Xcode on a device, but I have to assume that there is some way we can create that gets the logs off of a device for a user.
is it possible to access this directory on an iOS physical device in any way from outside Xcode to retrieve these logs?
It is possible to expose the Documents directory by enabling iTunes file sharing. When file sharing is enabled through this method, the contents of Documents directory would be visible to the user in iTunes, which can also be exported. The documents would also be visible for export through some third party desktop apps like iExplorer.
Here is the link to Apple documentation. You may also refer this thread to understand how this is done.
If you're using a simulator (apparently your task doesn't seem to need te real device) you are in luck.
You should go to a folder similar to this one:
/Users/[YOUR_USER_NAME]/Library/Developer/CoreSimulator/Devices/[RANDOM_HASH_YOU_SHOULD_DISCOVER]/data/Containers/Data/Application/[RANDOM_HASH_2_YOU_SHOULD_ALSO_DISCOVER]
Once there, with finder, you'll get the "documents" folder of the simulator and the app you're trying to retrieve your logs from.
You might say: I don't know which 2 RANDOM_HASHES should I go to.
Yes, you're right. If you have MANY simulators installed and or being used, it might be tricky to discover which one is the one you're trying to debug.
The same thing with your APP, your app will live in another RANDOM_HASH folder, and you should browse them, one by one, and then discover your documents folder.
Someone needed to solve this "mess" and created a Xcode Alcatraz Extension that leads you to the exact live simulator and APP you're debugging in any given moment, and then you don't need to guess which 2 random_hash paths you need to navigate to.
If Xcode + Alcartaz plugin extension manager is somewhat out of your reach, you might need to google it. It's not a difficult process.
PS: That magical Alcatraz Extension is named "XCodeWay" (in case you are brave enough to install Alcatraz onto your copy of XCode).
EDIT: Useful link to get Alcatraz: http://alcatraz.io/ Follow its easy instructions and you're done.
EDIT2: If Xcode cannot be used, then the last question in this other thread might come in handy: Browse the files created on a device by the IOS application I'm developing, on workstation?
(Still, an external application in your users machine will be needed )
For the project I work on, we have to set up performance metrics. The way we do it is that the simulator writes CSV files to a known location. We then retrieve theses files and make graphs out of it. Piece of cake.
We also have these tests running on the device. In that case, the files are created in the Documents directory.
While I can retrieve these files via the organizer, I'd be much more interested in automating that.
How can I retrieve files from an iPhone app via the command line rather than the organizer?
You can actually access the content of your app from your computer, using https://github.com/phonegap/ios-deploy (originally https://github.com/ghughes/fruitstrap) .
It's as simple as :
./ios-deploy --download=/Documents --bundle_id com.mycompany.myapp -2 dest_dir
You can do much more, like listing the content of the app, debug using lldb etc.
You can use iFuse, as part of libimobiledevice
You can not access the documents folder on your iOS device from your computer without itunes.
I run an webserver within my app so i can download the files via http. For zero configuration setup i use Apples Bonjour.
look here:
https://github.com/robbiehanson/CocoaHTTPServer
https://developer.apple.com/bonjour/
I'm doing some user tests of my new iOS app and store some test data in a plist. When I do that in the simulator it is easy to get that file for further analysis on my mac, but how can I easily get it from a real device? This will only be used during testing and will not be part of the final version.
Possible ways I have read about but not tried (in hope to get some directions here first):
E-mail attachment
Enable file transfer to iTunes
Jailbreak (but don't want to)
Currently what I am doing is to NSLog it and copy and paste from Xcode into Excel, but this requires that the device is tethered to my mac.
Any experience or advice on easiest way to get this done?
I sometimes use iPhone Explorer to do this, because the plist file I want is not in my Documents folder. I use it to navigate to the files associated with my app on the device. Just connect your device to your laptop, run iPhone Explorer and then use it to locate the plist file you want and drag and drop it wherever you want.
You can save data from Organizer. Just click on your device and it'll show in right pane. Files from documents folder and possibly other folders can be saved.