Adding images or videos to iPhone Simulator
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
You can add images and videos to the iPhone Simulator by dragging files onto the Simulator window, by using the xcrun simctl addmedia command, or by saving files from Safari within the Simulator. Each method places media into the Photos library where your app can access it through PhotoKit or UIImagePickerController.
Method 1: Drag and Drop
The fastest way to add media during development is to drag one or more files from Finder directly onto the running Simulator window.
- 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. You can drag multiple files at once. Supported formats include JPEG, PNG, HEIC, GIF, MOV, MP4, and M4V.
After the drop, open the Photos app inside the Simulator to confirm the import. If your app uses PHPhotoLibrary, the newly added asset will appear in query results immediately.
Method 2: xcrun simctl addmedia (Command Line)
The simctl addmedia command is the preferred approach when you need to script media imports or add files as part of a CI pipeline.
To find the UDID of a specific simulator, list all available devices:
This prints output like:
Scripting Bulk Imports
For test suites that require a specific photo library state, automate the import in a setup script:
Method 3: Save from Safari Inside the Simulator
If you need 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 method exercises the same permission prompts and save flow that real users encounter, making it useful for testing PHPhotoLibrary authorization dialogs.
Method 4: Programmatic Import in XCTest
For UI tests that need media available before each test run, you can add assets programmatically using simctl from within your test plan's setup:
Alternatively, use a pre-action script in your Xcode scheme's Test section to run xcrun simctl addmedia before the test bundle launches.
Comparison of Methods
| 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 |
Attempting to import an unsupported format (such as RAW .dng on older simulator runtimes) will fail silently with addmedia or show a brief error animation with drag-and-drop.
Resetting the Photo Library
During testing you may need to clear all media and start fresh. You have two options:
Option 1 resets everything including app installs and user defaults. Option 2 preserves your installed apps but requires a reboot for Photos to rebuild its database.
Common Pitfalls
Dragging files while the Simulator is locked. The import silently fails if the Simulator screen is on the lock screen. Unlock the Simulator first or use xcrun simctl addmedia, which bypasses the lock screen entirely.
Using 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.
Expecting persistent media after simctl erase. The erase command wipes all user data including Photos. If your CI pipeline erases the simulator between test runs, re-import media in the setup phase of each run.
Not waiting for import completion in scripts. xcrun simctl addmedia is synchronous and blocks until the import finishes, so you do not need a sleep after it. However, if you import a large number of files in a loop, the Photos indexer may still be processing when your test starts. Add a short delay or poll for asset count via PHPhotoLibrary in your test setup.
Path spaces without quoting. When using simctl addmedia in a script, file paths containing spaces must be quoted. Unquoted paths produce a "file not found" error for each word after the space.
Summary
Adding media to the iPhone Simulator comes down to two primary approaches: drag-and-drop for manual testing and xcrun simctl addmedia for automated workflows. The addmedia command accepts any iOS-compatible format, works on booted or specified simulators by UDID, and can be scripted into CI pipelines or XCTest pre-actions. For testing photo-permission flows, use the Safari save method. Always verify imports in the Photos app and remember that simctl erase wipes all media.
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 courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.