How do I add images to the iOS Simulator

22,350

Solution 1

  1. Run the simulator
  2. Run Safari on the Simulator
  3. Drag a picture onto Safari running on the Simulator, this opens the image.
  4. Click and hold on the image, or tap on the share icon in the bottom tool bar.
  5. You'll get an alert asking if you want to store the image to your phone

Solution 2

There is a slightly faster approach than what Abizern described

  1. Open the Simulator
  2. Drag an image directly onto it (no need to launch Safari.app)
  3. Safari willl launch
  4. Long-Press the image and save it to the Simulators Camera Roll

Update for iOS9: Locally stored images can be dragged directly onto the simulator and don't have to be saved explicitly.

enter image description here

Please note that your images are stored here (6.1 matches the Simulator version):

~/Library/Application Suppport/iPhone Simulator/6.1/Media/DCIM/100APPLE

Unfortunately you can't just add images to that folder as they will be ignored because they're not in the image database of the Simulator. However you can get all the stored images via the Finder.

Solution 3

With Xcode 6 is easier.

1.- Drag and drop an Image to the Simulator and the image will appear directly in the native Photos app.

Solution 4

You can also now do this through the command line with smctl addmedia command.

$ xcrun simctl addmedia
Usage: simctl addmedia <device> <path> [... <path>]

You can specify multiple files including a mix of photos and videos.

You can also specify multiple live photos by providing the photo and video files. They will automatically be discovered and imported correctly.

Note (you may not need to add xcrun in front of simctl depending on how command line tools are installed).

To find the correct device id, run simctl list devices

$ xcrun simctl list devices
== Devices ==
-- iOS 10.2 --
    iPhone 5 (D226CF12-6782-4D7D-9C00-2D662CF4022C) (Shutdown)
    iPhone 5s (34E0E0F8-3429-4D91-B038-ECF4FD0F3311) (Shutdown)
    iPhone 6 (9C772A68-34E3-4F3F-981C-543DE6D5D985) (Shutdown)
    iPhone 6 Plus (7848A50E-BFB5-4F19-BB31-4A56CA78AA2C) (Shutdown)
    iPhone 6s (12CF89BA-C8B2-4837-B4EB-FB24DFF1622C) (Shutdown)
    iPhone 6s Plus (3EE6CA84-8F12-4A5E-A31D-EF4BF3CCBDB2) (Shutdown)
    iPhone 7 (1EB3CE5D-849C-491C-9CAA-5E97B1BD89CE) (Booted)
    iPhone 7 Plus (94FEFD36-6EFF-4762-BD21-79B1F958F6C6) (Shutdown)
    iPhone SE (E8E8ECEB-34C0-44F0-B92E-57DCA91024F1) (Shutdown)
    iPad Retina (0DA5BF39-3DC7-49B3-BE9B-2FA756FCA725) (Shutdown)
    iPad Air (DAB9C2D3-8EBC-41DC-9C2D-0ECEC1D2FAE3) (Shutdown)
    iPad Air 2 (1E2DA170-5C2E-413C-831B-FA65524643D3) (Shutdown)
    iPad Pro (9.7 inch) (99F931A9-0708-4637-9294-6420DC7A149C) (Shutdown)
    iPad Pro (12.9 inch) (08CD02EB-C44A-4183-961A-EED89FF1C225) (Shutdown)
-- tvOS 10.1 --
    Apple TV 1080p (7EE393F2-C83E-467F-9802-3E5BFE7C2CA9) (Shutdown)
-- watchOS 3.1 --
    Apple Watch - 38mm (B8969533-D7CD-462E-9E76-511C08E8CC8E) (Shutdown)
    Apple Watch - 42mm (E16167D9-1007-438B-8812-CD97CE6ABECA) (Shutdown)
    Apple Watch Series 2 - 38mm (F59C0BB1-B4D0-47DD-B927-1BFD78DD78C0) (Shutdown)
    Apple Watch Series 2 - 42mm (7FE3AADD-94AB-46B9-A057-78F20F030999) (Shutdown)

So to add a video to my iPhone 7 simulator, I would use:

$ xcrun simctl addmedia 1EB3CE5D-849C-491C-9CAA-5E97B1BD89CE <path to video>

Solution 5

With the drag and drop feature you will lose all the metadata of the photos.

I've created a project that make it really easy to import assets to the simulator: MBAssetsImporter.

It enables you to import both videos and photos while preserving all the original metadata of the files.

Share:
22,350
wmichaelsen
Author by

wmichaelsen

Updated on July 09, 2022

Comments

  • wmichaelsen
    wmichaelsen almost 2 years

    I have xcode 4.5.1 and want to add photos to the iphone 6.0 simulator but cant find it. I have a folder named iphone simulator but it just contains 4.3.1. It may be because some months ago I drag almost everything in the application support to my extern hard drive to save some memory. Now when I drag it back it contains the 4.3.1 which I used before. Do I have to download something on new or what should I do? Thanks in advance!

  • Krishna Raj Salim
    Krishna Raj Salim over 10 years
    In simulator version >= 7.0, this won't work at the first time. But will work after once you have done as what 'Abizern' said. :)
  • Arnaud
    Arnaud about 10 years
    Actually, you can skip step 2, it will open Safari for you, whatever the current active app is (if any).
  • Shane
    Shane almost 9 years
    Great little app, this is without a doubt the best way to add photos AND videos en-mass.
  • Besi
    Besi over 8 years
    @KrishnaRajSalim: Actually, with my iOS 9 Simulator this still works. Remote images can be saved like described and local images can just be dragged onto the simulator and will then show up in photos (without explicitly saving them)
  • Brandon Tweed
    Brandon Tweed over 7 years
    Thank you! I was looking for a way to do this programmatically so that running automation wouldn't require manually dumping image files onto the sim for each environment.
  • Béatrice Cassistat
    Béatrice Cassistat over 6 years
    Best answer for live photos!
  • emrahgunduz
    emrahgunduz over 5 years
    If you are getting lost in the device list (like me), and need to find the active one: xcrun simctl list devices | grep Booted
  • Alex Buznik
    Alex Buznik almost 3 years
    Actually you can drop right to the Photos app