Adding images or videos to iPhone Simulator

170,976

Solution 1

The simplest way to get images, videos, etc onto the simulator is to drag and drop them from your computer onto the simulator. This will cause the Simulator to open the Photos app and start populating the library.


If you want a scriptable method, read on.

Note - while this is valid, and works, I think Koen's solution below is now a better one, since it does not require rebooting the simulator.

Identify your simulator by going to xCode->Devices, selecting your simulator, and checking the Identifier value. Or you can ensure the simulator is running and run the following to get the device ID xcrun simctl list | grep Booted

Go to

~/Library/Developer/CoreSimulator/Devices/[Simulator Identifier]/data/Media/DCIM/100APPLE

and add IMG_nnnn.THM and IMG_nnnn.JPG. You will then need to reset your simulator (Hardware->Reboot) to allow it to notice the new changes. It doesn't matter if they are not JPEGs - they can both be PNGs, but it appears that both of them must be present for it to work. You may need to create DCIM if it doesn't already exist, and in that case you should start nnnn from 0001. The JPG files are the fullsize version, while the THM files are the thumbnail, and are 75x75 pixels in size. I wrote a script to do this, but there's a better documented one over here(-link no longer work).

You can also add photos from safari in the simulator, by Tapping and Holding on the image. If you drag an image (or any other file, like a PDF) to the simulator, it will immediately open Safari and display the image, so this is quite an easy way of getting images to it.

Solution 2

Explain step by step of Airsource Ltd's answer for adding image to simulator:

  1. Drag it to simulator, then Safari opens (or browse to the Image in the internet using Safari)
  2. Hold your click on the image
  3. When the pop-up appears, choose Save Image and enjoy ;)

Update: for iOS Simulator 4.2, do these steps twice to get it work. Thanks kevboh!

Update: This also works for iOS Simulator 6.1

Solution 3

3 Simple Steps

  1. Drag & Drop image onto simulator
    - this will open a browser with your image
  2. Click & hold image
    - this will open options
  3. save image
    - this will copy image onto simulator

Watch YouTube Video ( add images to iphone simulator)

Solution 4

With iOS 8.0, we added the ability to just drag and drop images into the iOS Simulator. You can drag a bunch of images into the window, and they should be imported into the photo reel for that simulated device. You can also do this with the simctl command line tool. 'xcrun simctl addphoto '

Solution 5

Since Xcode 6 you can use the command line tool xcrun simctl.

Usage is very simple; to add a photo to the currently running simulator you use the booted placeholder.

xcrun simctl addmedia booted ./MyFile.jpg

To add it to any other simulator, you use its device id, which can be found by running xcrun simctl list.

xcrun simctl addmedia E201E636-CE6C-11E5-AB30-625662870761 ./MyFile.jpg
Share:
170,976

Related videos on Youtube

Vijayeta
Author by

Vijayeta

Updated on November 03, 2021

Comments

  • Vijayeta
    Vijayeta over 2 years

    I am trying to use UIImagePickerController with UIImagePickerControllerSourceTypePhotoLibrary, but it says, "No photos". Where does the simulator get the images from? Where should I copy the images so that they are displayed in the simulator?

    • Fattie
      Fattie over 10 years
      Drag images to the iPhone simulator. Then right-click on the image to save it.
    • Scott Rowley
      Scott Rowley about 10 years
      I couldn't right click it with the current sim but I could click the "Share" icon and then save the image.
    • erstaples
      erstaples almost 10 years
      Scott Rowley's response worked for me, and Joe Blow's didn't. I think this might be a Xcode 5.1.1 release difference.
  • Admin
    Admin over 14 years
    Under iPhone SDK 3.0, this has changed just a bit. Now, the thumbnail files (".THM") need to go under 100APPLE/.MISC. Otherwise, all the photos will appear as black boxes.
  • Simon Woodside
    Simon Woodside over 14 years
    How do I update the icon on the Saved Photos cell in the main Photo Album table view?
  • gak
    gak about 14 years
    My location is at ~/Library/Application Support/iPhone Simulator/3.1.3/Media/DCIM/100APPLE
  • Kamchatka
    Kamchatka almost 14 years
    how do you get the .thm files from images coming from an iPhone?
  • memmons
    memmons about 13 years
    Note: You can also add videos to the simulator using this method as well.
  • Dwhite
    Dwhite about 13 years
    This doesn't work for me with iOS simulator Version 4.2 (235). I can run through steps 1-3 fine, but when I go to "Photos" I don't see anything.
  • Dwhite
    Dwhite about 13 years
    This worked for me, but I needed to make a simple change to the app: Because I'm running the 4.2 simulator and this was designed to run on 4.0 (which I don't have), I went to "Project" -> "Edit Project Settings" and then under "Architectures" I changed the "Base SDK" to "Latest iOS".
  • Mukesh Nandeda Dhakad
    Mukesh Nandeda Dhakad almost 13 years
    This worked for me when I had no apps open, when I had an app open it went through the same steps but didn't actually work.
  • Talktobijju
    Talktobijju almost 13 years
    image format should be .jpg only..it would not work for .png i think
  • Eric Brotto
    Eric Brotto over 12 years
    I didn't see the folder named 100APPLE, so I made one. Still didn't work.
  • Bagusflyer
    Bagusflyer over 11 years
    Doesn't work for video. Because nothing happen when you long press the screen.
  • Dav Yaginuma
    Dav Yaginuma over 11 years
    For me with the 5.1 simulator, you don't need the .THM files and the directory needed to be ~/Library/Application Support/iPhone Simulator/5.1/Media/DCIM/100APPLE The script link in the answer was no longer working for me so I whipped up my own script here: gist.github.com/3738695
  • Dave Marley
    Dave Marley over 11 years
    Wow this was so easy it felt like I was cheating! BTW as noted by @KarenAnne, this works in iOS 6.0 simulator, with photos ending up in ~/Library/Application Support/iPhone Simulator/6.0/Media/DCIM/100APPLE and (it appears) no .THM files. In any case, great tip!
  • Kenny Grant
    Kenny Grant over 11 years
    Unfortunately with iOS6, this technique no longer works. This little importing app which you can run in the simulator works well though - aptogo.co.uk/2010/09/importing-photos See the lower rated answers below this one.
  • Craig Day
    Craig Day over 10 years
    Works perfectly with iOS7 as well. Nice answer.
  • Swindler
    Swindler over 10 years
    Excellent solution. I had dropped my photos in the Media/DCIM folder but I needed to also delete the PhotoData folder. And, this works for me with iOS 7 too.
  • Claudiu
    Claudiu over 10 years
    this should really be the accepted answer. screw messin' around with the file system.
  • Zorayr
    Zorayr over 10 years
    Deleting the *.sqlite- files worked for me. Thanks!
  • Klaas
    Klaas over 10 years
    Works for iOS7 as well! Thanks!
  • Ash
    Ash over 10 years
    Not working for me in iOS7 simulator - the solution relies on Safari to work, and Safari is not present in the iOS7 simulator.
  • Ash
    Ash over 10 years
    Doesn't work out-of-the-box under iOS7 - says something about cocoaPods being out of sync.
  • Ash
    Ash over 10 years
    Of the four methods I've tried under iOS7.0.3 4-inch simulator, this is the only one that worked, although I did find I got duplicates of every image. Upvoted.
  • Cristian Bica
    Cristian Bica over 10 years
    Well you must run pod install to install the pods as they are not in the repo. I've updated the README
  • Rob
    Rob over 10 years
    I was able to use this github project under iOS7.0 to import the images github.com/basilhe/iOS-Simulator-Photo-Importer. Seems to be a variant of the photo importer mentioned before, but also does videos.
  • Rob
    Rob over 10 years
    The images end out thumbnailed to 552x668 resolution, which isn't the original image. In contrast, the image importer preserves the original image resolution.
  • KarenAnne
    KarenAnne about 10 years
    Thanks! I was wondering why the photos I've transferred is not showing even if I already placed them in Media/DCIM/100APPLE. Turns out, there is an extra step of deleting Media/PhotoData folder.
  • KarenAnne
    KarenAnne about 10 years
    Yah, although I got duplicate images.. :O
  • KarenAnne
    KarenAnne about 10 years
    Read below user @user2966386's answer. Simpler and will not cause duplicates. :)
  • Anand
    Anand over 9 years
    Excellent, it really helped me. I tried several methods and till now I was doing drag and drop. But it is more easier way when you need to copy too many images :)
  • VaporwareWolf
    VaporwareWolf over 9 years
    With iOS 8, you can now drag photos onto the simulator :)
  • Jordan H
    Jordan H over 9 years
    Thanks! Great feature. Note that you can't drag them to the Dock icon, you have to drag them into the Simulator window. Hope that's changed soon to allow dragging to the icon.
  • Jeremy Huddleston Sequoia
    Jeremy Huddleston Sequoia over 9 years
    Dragging to the Dock icon should bring the app windows to the foreground (like if you drag to the Finder dock icon).
  • ThomasW
    ThomasW over 9 years
    @Ash I just checked and Safari is available in the iOS 7 simulator.
  • ThomasW
    ThomasW over 9 years
    I'm using Xcode 6 and Safari is no longer involved. Images go directly into the photo library.
  • Ash
    Ash over 9 years
    ThomasW, I can't check why I didn't have Safari in my simulator because I no longer have the same computer, but I believe it may have been missing due to having upgraded my Xcode from an older version. In any case, I recall at the time that the Safari icon itself was missing. Maybe a later update fixed the problem? My comment is almost a year old.
  • Paul Ardeleanu
    Paul Ardeleanu over 9 years
    You can now also drag, in one go, multiple photos straight into the Camera Roll album.
  • nadeem gc
    nadeem gc over 9 years
    Does not make a difference in IOS 8.1
  • Eric G
    Eric G about 9 years
    This was super delightful to find out today, especially for testing performance of collection views with a huge amount of image data + NSCache optimization.
  • Steven Fisher
    Steven Fisher about 9 years
    Unlike Arel's answer, movies moved into DCIM/100APPLE will not become available with this technique.
  • julien_c
    julien_c about 9 years
    Hi @JeremyHuddlestonSequoia! Two questions: the command only works for pictures, not videos, right? Also, is there any way to input "moment"-style information to the simulator (i.e., create multiple moments, possibly backdated, etc.)?
  • Jeremy Huddleston Sequoia
    Jeremy Huddleston Sequoia about 9 years
    Correct. It is just for adding photos. It cannot be used for videos. I'm not aware of a way to backdate the events, but that may be possible through the Photos app. If not, it would certainly be worth filing a radar for at bugreport.apple.com
  • Mati Bot
    Mati Bot almost 9 years
    @PaulArdeleanu, you are right. However, it doesn't preserve you original metadata of the assets. Please have a look at my projects that helps you import your assets while preserving all the metadata github.com/matibot/MBAssetsImporter
  • Mati Bot
    Mati Bot almost 9 years
    @JeremyHuddlestonSequoia, It doesn't preserve the original metadata of the assets. Please have a look at my project that helps you import your assets while preserving all the metadata (Including videos!) github.com/matibot/MBAssetsImporter
  • Jeremy Huddleston Sequoia
    Jeremy Huddleston Sequoia almost 9 years
    @MatiBot Please give Xcode 7 a try. Metadata should be preserved when importing in Xcode 7.
  • Jeremy Huddleston Sequoia
    Jeremy Huddleston Sequoia almost 9 years
    Yes, it certainly is ;) BTW, Please file a radar at bugreport.apple.com requesting video import as well.
  • Tony
    Tony over 8 years
    Looks like there's 'xcrun simctl addvideo' now! This is great!
  • user2067021
    user2067021 about 8 years
    @MatiBot, MBAssetsImporter is great for bulk transfer of images - thanks very much!
  • prolfe
    prolfe over 7 years
    This answer should be unaccepted as it doesn't work with newer iOS environments. The simplest solution is mine below: stackoverflow.com/a/41884742/2813408
  • Airsource Ltd
    Airsource Ltd over 7 years
    Hardly. The answer needs a path change to continue to work, and the correct thing to do is edit the existing answer to modify the path. Your answer is a completely different approach, and only simpler if you hate the command line.
  • Fabiano Neumann
    Fabiano Neumann almost 7 years
    "You can also add photos from safari in the simulator, by Tapping and Holding on the image. If you drag an image (or any other file, like a PDF) to the simulator, it will immediately open Safari and display the image, so this is quite an easy way of getting images to it." Awesome, thanks!
  • russbishop
    russbishop almost 7 years
    FYI: I added Live Photo importing to Xcode 8.3. Now dragging the photo and video for a Live Photo into the Simulator window (or using the new simctl addmedia command) they should import as a Live Photo, not as separate photo and videos.
  • Raphael
    Raphael almost 7 years
    "You will then need to reset your simulator " -- Since Simulater > Reset Content and Settings is not meant here, maybe reword?
  • Raphael
    Raphael almost 7 years
  • StackUnderflow
    StackUnderflow over 6 years
    The last command "xcrun simctl addmedia E201E636-CE6C-11E5-AB30-625662870761 ./MyFile.jpg" only seem to work if the simulator is running. I was hoping there would be a solution to add images without running i.e. to prepare before running a simulator.
  • Sethmr
    Sethmr over 5 years
    If anyone is looking for which simulator has which UDID check the path ~/Library/Developer/CoreSimulator/Devices/device_set.plist
  • Todanley
    Todanley over 5 years
    Works with Xcode 10. Please note: it does not work with multiple images, you have to drag one at a time.
  • Antzi
    Antzi over 5 years
    The only drawbacks is that it doesn't work with multiple images at once.
  • endavid
    endavid over 5 years
    This has stopped working on XCode 10 (tested on 10.1), iOS 12.1 :(
  • Dazzle
    Dazzle almost 5 years
    Works with multiple images fine. Can't believe I didn't know this sooner.
  • Buraco
    Buraco over 3 years
    For drag and drop operation, it is important to know that some directories has no read / write access for example "Downloads". So dragging from downloads and dropping onto simulator throws an error.
  • Evan
    Evan over 3 years
    thank you lol the documents folder was the key here
  • Barb
    Barb over 2 years
    Thank you so much! This saved me a lot of time!
  • Ron Sims II
    Ron Sims II about 2 years
    This approach works for Big Sur if you get the following error while trying to drag and drop a photo onto the simulator: The operation couldn’t be completed. (PHPhotosErrorDomain error -1.)