Skip to content

Instantly share code, notes, and snippets.

@yannxou
Last active September 5, 2024 09:11
Show Gist options
  • Save yannxou/281c82a1d8fe297971bd25954858c15f to your computer and use it in GitHub Desktop.
Save yannxou/281c82a1d8fe297971bd25954858c15f to your computer and use it in GitHub Desktop.
Add files to iOS simulator

How to add files to the iOS simulator

Tested with macOS Ventura and xcode 14.

Files can be added by:

A. Drag & drop the file to the iOS simulator

This is the easy way but image/video files are always added to the Photos app. Other kind of files like PDF are added to the Files app.

B. Running the simctl command:

Example: xcrun simctl addmedia booted pic.001.jpg

This has the same behaviour as option 1 but can be automated.

C. Copying to the File Provider Storage directory:

username/Library/Developer/CoreSimulator/Devices/*device_hash_folder*/data/Containers/Shared/AppGroup/*hash_folder*/File Provider Storage/

This allows copying any kind of file so it's available in the Files app (locally on my iPhone folder).

The following script opens the File Provider Storage of the currently booted simulator:

SIM_UDID=$(xcrun simctl list devices | grep Booted | perl -n -e'/^.*([0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}).*$/ && print $1')
FILES_PATH=$(xcrun simctl listapps $SIM_UDID | grep LocalStorage | awk -F'"' '{print $4}' | sed -e "s/^file:\/\///")
open $FILES_PATH/File\ Provider\ Storage
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment