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
- Launch the Simulator (from Xcode or via
open -a Simulator). - Locate the image or video file in Finder.
- 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.
To find a simulator's UDID, list the devices:
This prints output like:
Seeding a photo library in bulk
For test suites that need a specific photo library state, run a setup script:
Saving from Safari inside the Simulator
To test the full user flow of saving an image from the web:
- Open Safari inside the Simulator.
- Navigate to any URL hosting the image (even
file://URLs work for local files served viapython3 -m http.server). - 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:
The media is in the Photos library before the test bundle launches.
Which method to use
| Method | Best for | Automatable | Requires Simulator running | Formats |
| Drag and drop | Quick manual testing | No | Yes | All iOS-supported media |
xcrun simctl addmedia | CI pipelines, scripted setup | Yes | Yes | All iOS-supported media |
| Safari save | Testing real user save flows | No | Yes | Web-hosted images |
| XCTest pre-action | Per-test-suite media seeding | Yes | Yes | All iOS-supported media |
Supported file formats
| Type | Supported formats |
| Images | JPEG, PNG, HEIC, HEIF, GIF, TIFF, BMP, WebP (iOS 14+) |
| Videos | MOV, MP4, M4V |
| Live Photos | Paired 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
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.
Related reading
- Adding iOS UITableView HeaderView not section header
- Adding padding to an UIView
- Adding rounded corner and drop shadow to UICollectionViewCell
- Adding space/padding to a UILabel
- AKS Primes algorithm in Python
- Amazon Kinesis Integration Tests
- Adding the Clear Button to an iPhone UITextField
- Adding the little arrow to the right side of a cell in an iPhone TableView Cell
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseNo 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 courseData 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.