Document folder iOS Simulator
Asked Answered
K

4

46

How is possible to find quickly the document folder (in the mac) of an App when I'm using the simulator? When I need to explore the document folder during the simulation of the App now I use a variable of the App to find the document folder path and I read the path during the debug (using a variable) but I think is not the best solution.

Kaciekacy answered 12/3, 2016 at 22:11 Comment(10)
Try the SimulatorManager. It's a Mac app that display an icon in the task bar with all simulator devices in the menu and allow you to browse apps document sandbox installed on each simulator. http://tue-savvy.github.ioPteranodon
If you're developing only one app then there is only one folder beyond ~Libraries/Application Support/iPhoneSimulator (I have to check the path).Zasuwa
the path seems doesn't exist..Kaciekacy
But the App is compatible only with XCode 6 and I use XCode7...Kaciekacy
It works for me on XCode 7 / El capitan. You need to compile and install it.Pteranodon
Yes I'm trying it... it seems more easy than the plugin...Kaciekacy
Yes it works correctly ... is a little bit slow at opening but it works.. thanks!Kaciekacy
Try ~/Library/Application\ Support/iPhoneSimulatorHokeypokey
nothing to do.. the path doesn't exist. I solved using the mac App SimulationManager. Thanks anywayKaciekacy
See ~/Library/Application Support/iPhone Simulator/7.1/Applications when you're developing for 7.1. When you're developing for 8.0 then check for 8.0. When you change to a directory, you can check for other dirs available by pressing ~/Library/App<tab>.Zasuwa
H
134

Set and hit a breakpoint in the app, and write the following in the Xcode Console (next to the Variables View):

po NSHomeDirectory()

Then in Finder hit Shift+CMD+G, paste the path returned above without the quotation marks and hit enter.

Had answered 1/6, 2016 at 15:32 Comment(2)
This throws a compiler error for me; adjusting it to var homeDir = NSHomeDirecotry; print(homeDir) (or examining the value of homeDir at a break point) works though.Mande
@AlexHall This answer says to write this command in the console while paused at a break point. I misread it at first too and thought it meant to put this command in your code.Flossi
K
29

Open up Terminal.app and run:

xcrun simctl get_app_container booted [app identifier] data

You can even setup an alias to change to the directory, like:

alias cdmyapp='cd $(xcrun simctl get_app_container booted com.mycompany.myapp data)'
Kelt answered 13/3, 2016 at 6:54 Comment(6)
I like the alias idea! But this is just the bundle folder, not the Documents folder.Viewable
This is awesome. May I know where can I get the list of other such functions (e.g get_app_container)? I'm basically looking to fetch Documents Directory from command line. Any Help?Bender
This returns the .app bundle not the documents/data directory as the question asksGuideboard
Great answer, in the modern Xcode environment I think this is probably the fastest way.Attorneyatlaw
cd $(xcrun simctl get_app_container booted [app identifier] data) to get to the documents folderWindsor
open $(xcrun simctl get_app_container booted com.guidebook.guidebook data)/Documents to open de documents folder. Notice data and /Documents.Lordly
S
6

I have 2 solution

  • Simpholders or free and open source alternative OpenSim
  • A simple script that opens the finder window with the recently launched application on the iOS simulator

deviceId=$(xcrun simctl list devices | grep Booted | sed -n 's/^.([A-F0-9]{8}-([A-F0-9]{4}-){3}[A-F0-9]{12}).$/\1/p') applicationFolder=~/Library/Developer/CoreSimulator/Devices/$deviceId/data/Containers/Data/Application/ applicationFolder=$applicationFolder$(ls -Art $applicationFolder | tail -n 1) open $applicationFolder

Sabbath answered 26/5, 2017 at 8:50 Comment(0)
M
0

This is the best I could do:

echo "Documents directory"
device_id=$(xcrun simctl list devices | grep Booted | sed -n 's/^.*\([A-F0-9]\{8\}-\([A-F0-9]\{4\}-\)\{3\}[A-F0-9]\{12\}\).*$/\1/p')
for folder in ~/Library/Developer/CoreSimulator/Devices/$device_id/data/Containers/Shared/AppGroup/*; do
  documents_directory="$folder/File Provider Storage"

  if [[ -a "$folder/File Provider Storage" ]]; then
    echo $documents_directory
    break
  fi
done
Mcgruder answered 22/5 at 13:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.