iPhone Simulator
Adding Media
iOS Development
Xcode
iOS Testing

How to add photos and videos to the iOS Simulator

Codemia Knowledge Hub ·

To add images or videos to the iPhone Simulator, drag the files onto the Simulator window, run xcrun simctl addmedia, or save them from Safari inside the Simulator. Every method puts the media in the Photos library, where your app can reach it through PhotoKit or UIImagePickerController.

Drag and drop from Finder

  1. Launch the Simulator (from Xcode or via open -a Simulator).
  2. Locate the image or video file in Finder.
  3. Drag it onto the Simulator window.

The Simulator imports the file into the Photos app automatically, and you can drag multiple files at once. Supported formats include JPEG, PNG, HEIC, GIF, MOV, MP4, and M4V.

Open Photos inside the Simulator to confirm the import. If your app uses PHPhotoLibrary, the new asset appears in query results immediately.

xcrun simctl addmedia from the command line

Use simctl addmedia when you want to script imports or run them in CI.

bash
1# Add a single image to the currently booted simulator
2xcrun simctl addmedia booted ~/Desktop/test-photo.jpg
3
4# Add multiple files at once
5xcrun simctl addmedia booted photo1.png photo2.png video.mp4
6
7# Target a specific simulator by UDID
8xcrun simctl addmedia 4A2B3C4D-5E6F-7890-ABCD-EF1234567890 ~/assets/hero.png

To find a simulator's UDID, list the devices:

bash
xcrun simctl list devices

This prints output like:

 
-- iOS 17.5 --
    iPhone 15 Pro (4A2B3C4D-5E6F-7890-ABCD-EF1234567890) (Booted)
    iPhone SE (3rd generation) (1A2B3C4D-...) (Shutdown)

Seeding a photo library in bulk

For test suites that need a specific photo library state, run a setup script:

bash
1#!/bin/bash
2# seed-simulator-media.sh
3SIMULATOR_UDID="$1"
4MEDIA_DIR="./test-fixtures/media"
5
6# Boot if not already running
7xcrun simctl boot "$SIMULATOR_UDID" 2>/dev/null
8
9# Import all test assets
10for file in "$MEDIA_DIR"/*; do
11  xcrun simctl addmedia "$SIMULATOR_UDID" "$file"
12done
13
14echo "Imported $(ls "$MEDIA_DIR" | wc -l | tr -d ' ') files"

Saving from Safari inside the Simulator

To test the full user flow of saving an image from the web:

  1. Open Safari inside the Simulator.
  2. Navigate to any URL hosting the image (even file:// URLs work for local files served via python3 -m http.server).
  3. Long-press the image and tap "Add to Photos" or "Save Image."

This goes through the same permission prompts and save flow real users see, which makes it useful for testing PHPhotoLibrary authorization dialogs.

Importing media before UI tests

XCTest code runs inside the iOS simulator, where Process is unavailable, so it cannot call simctl. Run it from the Mac side instead: add a pre-action script to the Test section of your Xcode scheme, and set "Provide build settings from" to your test target so SRCROOT resolves:

bash
xcrun simctl addmedia booted "${SRCROOT}/TestFixtures/test-image.jpg"

The media is in the Photos library before the test bundle launches.

Which method to use

MethodBest forAutomatableRequires Simulator runningFormats
Drag and dropQuick manual testingNoYesAll iOS-supported media
xcrun simctl addmediaCI pipelines, scripted setupYesYesAll iOS-supported media
Safari saveTesting real user save flowsNoYesWeb-hosted images
XCTest pre-actionPer-test-suite media seedingYesYesAll iOS-supported media

Supported file formats

TypeSupported formats
ImagesJPEG, PNG, HEIC, HEIF, GIF, TIFF, BMP, WebP (iOS 14+)
VideosMOV, MP4, M4V
Live PhotosPaired HEIC + MOV with matching asset identifier

An unsupported format (such as RAW .dng on older simulator runtimes) fails silently with addmedia or shows a brief error animation with drag-and-drop.

Resetting the photo library

bash
1# Option 1: Erase all content and settings (nuclear option)
2xcrun simctl erase booted
3
4# Option 2: Delete only the Photos database
5rm -rf ~/Library/Developer/CoreSimulator/Devices/<UDID>/data/Media/DCIM
6rm -rf ~/Library/Developer/CoreSimulator/Devices/<UDID>/data/Media/PhotoData
7# Then reboot the simulator
8xcrun simctl shutdown booted && xcrun simctl boot <UDID>

Option 1 resets everything, including app installs and user defaults. Option 2 keeps your installed apps but needs a reboot so Photos can rebuild its database.

When imports fail or media goes missing

The Simulator is on the lock screen. Dragged files silently fail to import. Unlock it first, or use xcrun simctl addmedia, which bypasses the lock screen.

Unsupported codecs. Some MOV files encoded with ProRes or other professional codecs will not import. Transcode to H.264/AAC first with ffmpeg -i input.mov -c:v libx264 -c:a aac output.mp4.

simctl erase wipes Photos. If CI erases the simulator between runs, re-import media in each run's setup.

The Photos indexer lags behind. xcrun simctl addmedia is synchronous, so no sleep is needed after it. After importing many files in a loop, though, the indexer may still be working when the test starts. Add a short delay or poll the asset count via PHPhotoLibrary in your setup.

Unquoted paths with spaces. In scripts, quote file paths that contain spaces, or simctl addmedia reports "file not found" for each word after the space.


Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Basis Lab
No course covers this one yet

Basis Lab writes one for you from a sentence about what you want to be able to do, then teaches it and checks you understood. Your first course is free.

Build my course
Data Structures & Algorithms practice on Codemia

Step through 300+ coding interview problems with animated visualisers that show the data structure changing as the code runs. The Blind 75 are free.

Practice algorithms