312

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?

iwasrobbed
  • 46,496
  • 21
  • 150
  • 195
Vijayeta
  • 5,585
  • 5
  • 21
  • 11

35 Answers35

454

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

Khattab
  • 737
  • 1
  • 10
  • 20
KONG
  • 7,271
  • 6
  • 28
  • 27
  • 1
    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. – Mark Fowler Feb 28 '11 at 07:58
  • 2
    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. – Tristan Warner-Smith Jul 11 '11 at 09:25
  • image format should be .jpg only..it would not work for .png i think – Talktobijju Jul 13 '11 at 07:33
  • 1
    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! – Dave Marley Oct 28 '12 at 19:49
  • Works perfectly with iOS7 as well. Nice answer. – Craig Day Sep 11 '13 at 13:40
  • this should really be the accepted answer. screw messin' around with the file system. – Claudiu Oct 17 '13 at 18:54
  • Not working for me in iOS7 simulator - the solution relies on Safari to work, and Safari is not present in the iOS7 simulator. – Ash Dec 30 '13 at 11:30
  • @Ash I just checked and Safari is available in the iOS 7 simulator. – ThomasW Sep 25 '14 at 09:40
  • I'm using Xcode 6 and Safari is no longer involved. Images go directly into the photo library. – ThomasW Sep 25 '14 at 09:41
  • 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. – Ash Sep 26 '14 at 07:50
284

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.

Anand Rockzz
  • 6,072
  • 5
  • 64
  • 71
Airsource Ltd
  • 32,379
  • 13
  • 71
  • 75
  • 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. –  Sep 03 '09 at 21:50
  • How do I update the icon on the Saved Photos cell in the main Photo Album table view? – Simon Woodside Nov 03 '09 at 20:39
  • 3
    My location is at `~/Library/Application Support/iPhone Simulator/3.1.3/Media/DCIM/100APPLE` – gak Apr 07 '10 at 03:26
  • how do you get the .thm files from images coming from an iPhone? – Kamchatka Jun 15 '10 at 23:23
  • Note: You can also add videos to the simulator using this method as well. – memmons Feb 25 '11 at 02:45
  • I didn't see the folder named 100APPLE, so I made one. Still didn't work. – Eric Brotto Oct 09 '11 at 17:18
  • 3
    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: https://gist.github.com/3738695 – Dav Yaginuma Sep 17 '12 at 17:38
  • 11
    Unfortunately with iOS6, this technique no longer works. This little importing app which you can run in the simulator works well though - http://aptogo.co.uk/2010/09/importing-photos/ See the lower rated answers below this one. – Kenny Grant Dec 20 '12 at 19:55
  • This answer should be unaccepted as it doesn't work with newer iOS environments. The simplest solution is mine below: http://stackoverflow.com/a/41884742/2813408 – prolfe Jan 26 '17 at 23:21
  • 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. – Airsource Ltd Jan 27 '17 at 08:42
  • "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! – Fabiano Neumann May 15 '17 at 13:40
  • "You will then need to reset your simulator " -- Since `Simulater > Reset Content and Settings` is not meant here, maybe reword? – Raphael Aug 02 '17 at 15:53
  • Anyway, [it's a lot simpler nowadays](https://stackoverflow.com/a/25758880/539599). – Raphael Aug 02 '17 at 16:15
  • If anyone is looking for which simulator has which UDID check the path ~/Library/Developer/CoreSimulator/Devices/device_set.plist – Sethmr Sep 25 '18 at 19:05
  • 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. – Buraco Oct 13 '20 at 07:17
131

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)

Nicktar
  • 5,548
  • 1
  • 28
  • 43
user380427
  • 1,329
  • 1
  • 8
  • 2
64

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 '

Jeremy Huddleston Sequoia
  • 22,938
  • 5
  • 78
  • 86
  • 2
    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. – Jordan H Sep 21 '14 at 06:55
  • Dragging to the Dock icon should bring the app windows to the foreground (like if you drag to the Finder dock icon). – Jeremy Huddleston Sequoia Sep 22 '14 at 22:06
  • 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.)? – julien_c Apr 21 '15 at 14:46
  • 1
    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 http://bugreport.apple.com – Jeremy Huddleston Sequoia Apr 21 '15 at 16:28
  • @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!) https://github.com/matibot/MBAssetsImporter – Mati Bot Jul 27 '15 at 18:26
  • @MatiBot Please give Xcode 7 a try. Metadata should be preserved when importing in Xcode 7. – Jeremy Huddleston Sequoia Jul 28 '15 at 01:04
  • Yes, it certainly is ;) BTW, Please file a radar at http://bugreport.apple.com requesting video import as well. – Jeremy Huddleston Sequoia Jul 28 '15 at 08:22
  • Looks like there's 'xcrun simctl addvideo' now! This is great! – Tony Jan 27 '16 at 07:18
  • 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. – russbishop May 17 '17 at 20:36
  • Works with Xcode 10. Please note: it does not work with multiple images, you have to drag one at a time. – Todanley Sep 25 '18 at 22:36
52

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
Airsource Ltd
  • 32,379
  • 13
  • 71
  • 75
Koen.
  • 25,449
  • 7
  • 83
  • 78
  • 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. – StackUnderflow Dec 11 '17 at 10:30
27

Its simple. Just follow these steps :

  1. Drag and drop image onto Simulator
  2. Now image opens into Safari browser (file://.../ImageName). Tap-and-hold on the Image.
  3. This displays actionSheet with Save, Cancel option (Also copy in case of iOS 7 simulator).

    Screenshot for Actionsheet

  4. Save the image. The image gets added into Library.

    Photo Library

Jayprakash Dubey
  • 35,723
  • 18
  • 170
  • 177
23

I just stumbled upon how to bulk upload images on the iOS Simulator. (I've only confirmed it on 6.1.)

  1. Backup the folder:

    ~/Library/Application Support/iPhone Simulator/6.1/Media
    
  2. Copy all your images into the folder:

    ~/Library/Application Support/iPhone Simulator/6.1/Media/DCIM/100APPLE
    
  3. Move or delete the folder:

    ~/Library/Application Support/iPhone Simulator/6.1/Media/PhotoData
    
  4. Restart iOS Simulator

  5. Open the Photos app

The simulator will restore all the images from the 100APPLE folder!

Arel
  • 1,339
  • 17
  • 22
  • 1
    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. – Swindler Sep 19 '13 at 05:21
  • Works for iOS7 as well! Thanks! – Klaas Dec 14 '13 at 13:40
  • 1
    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. – Ash Dec 30 '13 at 11:46
  • 1
    I was able to use this github project under iOS7.0 to import the images https://github.com/basilhe/iOS-Simulator-Photo-Importer. Seems to be a variant of the photo importer mentioned before, but also does videos. – Rob Jan 09 '14 at 18:22
  • 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 Mar 27 '14 at 08:35
  • Yah, although I got duplicate images.. :O – KarenAnne Mar 27 '14 at 08:36
  • Read below user @user2966386's answer. Simpler and will not cause duplicates. :) – KarenAnne Mar 27 '14 at 08:46
21

For iOS 7 I did the following:

copy photos to these two folders:

~/Library/Application Support/iPhone Simulator/6.1/Media/DCIM/100APPLE
~/Library/Application Support/iPhone Simulator/7.0/Media/DCIM/100APPLE

delete these 4 files only (to avoid duplicates on relaunch):

~/Library/Application Support/iPhone Simulator/6.1/Media/PhotoData/Photos.sqlite-shm
~/Library/Application Support/iPhone Simulator/6.1/Media/PhotoData/Photos.sqlite-wal
~/Library/Application Support/iPhone Simulator/7.0/Media/PhotoData/Photos.sqlite-shm
~/Library/Application Support/iPhone Simulator/7.0/Media/PhotoData/Photos.sqlite-wal
user2966386
  • 211
  • 2
  • 2
18

Just drag images to the iPhone simulator.

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
Mihail Salari
  • 1,471
  • 16
  • 17
16

This is MUCH easier with the new iOS Simulator that comes with Xcode 6+ (iOS Simulator 8.1 and above.) Now all you have to do is drag one or more photos onto the iOS Simulator window, and instead of opening Safari, the Photos app opens, and instantly adds all dragged-in photos to the device.

Donald Burr
  • 2,281
  • 2
  • 23
  • 31
15

If you can not drag and drop your files because you experience the error:

One or more media items failed to import: : The operation couldn’t be completed. (PHPhotosErrorDomain error -1.)

Move your files into the Documents folder and then drag them into the simulator. This will trigger the simulator to ask for permissions to access your files. Having them inside the Downloads folder, will not.

Nicolai Lissau
  • 7,298
  • 5
  • 43
  • 57
12

Method 1 (Easiest Way): If you have your image on Mac

You can drag an image from the Finder on your Mac to Simulator, and it is saved to the Saved Photos album.

Method 2: If its on any URL

To save an image from a webpage to the Photos app

  1. Place the pointer on the image you want to save, and hold down the mouse button or trackpad.
  2. When the menu appears, click Save Image to save the image to the Photos app in an iOS simulator.
  3. The image is saved to the Saved Photos album in the Photos app.

Incase someone looking for Apple Documentation regarding Copying and Pasting in Simulator. Save Image from Safari

Ammar Mujeeb
  • 1,222
  • 18
  • 21
9

None of the answers had the exact solution that I needed.

The steps I've found for myself working on iOS 5.0 and above simulator are as follows:

  1. Close the simulator if it is running xcode project.

  2. Run simulator from the dock by clicking on it.

  3. Drag & drop the image into simulator.

  4. Tap and hold the image (opened in safari) and select the save option.

You are done.

Arshad Parwez
  • 1,563
  • 2
  • 19
  • 29
  • The images end out thumbnailed to 552x668 resolution, which isn't the original image. In contrast, the image importer preserves the original image resolution. – Rob Jan 09 '14 at 18:24
7

For iOS 5.1 this is further changed to new path

~/Library/Application Support/iPhone Simulator/5.1/Media/DCIM/100APPLE

antyrat
  • 27,479
  • 9
  • 75
  • 76
Deepak Keswani
  • 117
  • 1
  • 3
7

As of iOS 8, you can just drag all your photos onto the simulator window and they'll save to camera roll automatically. You can do as many at a time as you want.

bcherry
  • 7,150
  • 2
  • 28
  • 37
  • This was super delightful to find out today, especially for testing performance of collection views with a huge amount of image data + NSCache optimization. – Eric G Feb 19 '15 at 18:47
  • This has stopped working on XCode 10 (tested on 10.1), iOS 12.1 :( – endavid Dec 11 '18 at 13:36
7

None of the answers above worked for me on iOS 15.

I simply opened Files app and dragged and dropped the image there. It automatically imported the image to the Photos app and I was able to use everywhere through my simulator.

Cheers!

paprika
  • 164
  • 1
  • 8
6

For iOS 8, If there is no need to retain photo capture date and location, just drop photo files to the simulator.

To retain photo meta data, do the following:

  1. Copy photo files to: /Users/{USER}/Library/Developer/CoreSimulator/Devices/{UDID}/data/Media/DCIM/100Apple
  2. Remove (or rename) folder: /Users/{USER}/Library/Developer/CoreSimulator/Devices/{UDID}/data/Media/photoData
  3. Relaunch Simulator

Note: You need to replace {USER} with your user name and {UDID} with the UDID of the simulator. To find UDID for your simulator, from Terminal, run 'xcrun simctl list'.

Joe Smith
  • 1,900
  • 1
  • 16
  • 15
6

If you need to import more than just one or two photos then take a look at this article that I wrote. It describes an easy way to perform a bulk import of photos and works for iOS 4.x.

Robin Summerhill
  • 13,695
  • 3
  • 41
  • 37
  • 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". – Mark Fowler Feb 28 '11 at 08:24
4

In OS X Catalina with Xcode 11 you have to do this differently.

First you MUST start the simulator. If you want to copy, say a photo to MULTIPLE simulated devices. Start all of them up. Then Right Click on a SINGLE (Multiple images will fail. ONLY does a single file.).

Share -> Simulator

A 'share sheet will pop-up. You must choose an active simulator in the combo box and hit send.

It will send one to many but NOT many to many of selected photos.

I hope this helps folks. Drag and drop was supported in the last versions of Xcode and OS X but not with OS X Catalina and Xcode 11.

While this IS in the directions it currently IS NOT working.

What DID work for me was to first import my images into iPhoto on OS X and then DRAG/DROP them from my OS X iPhoto and drop into the simulator. It would appear the drag/drop for photos into the simulator is CURRENTLY only working from OS X iPhoto. :-(

Waxhaw
  • 599
  • 5
  • 9
3
quit the simulator.

Run simulator from the dock by clicking on it.

Drag & drop the image into simulator which you want to add.

it will open image in safari .

tap and hold the image and click the save option.

then open gallery and you will see the image which u had saved recently.
C_compnay
  • 133
  • 1
  • 4
3

Adding an image to the Iphone Simulation running IOS 8.0 is even easier.

  • Drag your image to the simulator
  • IOS opens the Photo app and your image is now part of your collection.

No need to deal with Safari anymore

Thomas
  • 1,956
  • 14
  • 21
  • You can now also drag, in one go, multiple photos straight into the Camera Roll album. – Paul Ardeleanu Nov 10 '14 at 14:43
  • 1
    @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 https://github.com/matibot/MBAssetsImporter – Mati Bot Jul 27 '15 at 18:24
  • 1
    @MatiBot, MBAssetsImporter is great for bulk transfer of images - thanks very much! – user2067021 Apr 06 '16 at 05:55
2

try this app I've made. download the code and run it in simulator https://github.com/cristianbica/CBSimulatorSeed

Cristian Bica
  • 4,067
  • 27
  • 28
2

For iOS 8.0,the answer is out of date.I found the media resource in the following path: ~/Library/Developer/CoreSimulator/Devices/[DeviceID]/data/Media/DCIM/100APPLE

tbago
  • 660
  • 1
  • 6
  • 19
2
  1. Using your pc just Send the image via your email
  2. Open the IOS-Simulator then open the email and download the image

  3. just click and hold the mouse on the image, and from the options that will be displayedenter image description here

  4. Then, it will be automatically saved to your iOS-Simulator's photo gallery

Assegd
  • 106
  • 18
  • 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.) – Ron Sims II Mar 23 '22 at 13:59
2

For iOS 4.2 I had to go and create the 100APPLE folder and restart the simulator, then it worked.

fredley
  • 32,953
  • 42
  • 145
  • 236
sabross
  • 29
  • 1
1

Just Drag and Drop image into iphone simulator. browser will open to show your image. press on image until you not receive options to save Image. then Save image. thats it :). you will see your image in to Photo app in your simulator....

Bhagirath
  • 27
  • 1
1

I wrote a bash script to do this. Check the link[1]

#!/bin/bash

# Imports pictures into all iOS simulators.

path_to_pic="src/ios/pictures/"

mkdir -p /Users/$(whoami)/Library/Application\ Support/iPhone\ Simulator/{5.0,5.1,6.0,6.1}/Media/DCIM/100APPLE/
find ~/Library/Application\ Support/iPhone\ Simulator/ -type d -name '100APPLE' -exec cp /Users/$(whoami)/$path_to_pic/* {} \;

[1] : https://gist.github.com/firesofmay/5194901

firesofmay
  • 582
  • 1
  • 3
  • 16
1

Just to tell you : KONG's solution also works on iOS 7 beta.

His solution was:

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

mathgag555
  • 39
  • 2
1

I just needed some random images for testing, so this is how I did it.

I have the simplest solution in the world. Just open Safari in the simulator, go to Google images (or your own web or Dropbox URL), view an image, hold down the mouse button for 2 seconds, and you'll see "Save Image" - it will save right into the Photos library. Rinse and repeat.

Justin Schier
  • 524
  • 5
  • 14
1

an even easier way, is : open safari on simulator > tap www.google.com search for random photos "nature" open each image, press on it and save it.

blackmoon
  • 362
  • 1
  • 11
1

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.

Mati Bot
  • 797
  • 6
  • 13
1

1. CD to this path:

/Users/[macOS user]/Library/Developer/CoreSimulator/Devices/[Simulator Identifier]/data/Media/DCIM/100APPLE

[Simulator Identifier] or UDID can be found at : Hardware => device => manage devices.

eg. cd /Users/rnDeveloper/Library/Developer/CoreSimulator/Devices/7508171A-DC5D-47CF-9BE1-FF950326E3DB/data/Media/DCIM/100APPLE

2. Download photo by run this command:

curl -o pic_001.jpg "https://s-media-cache-ak0.pinimg.com/474x/49/25/7a/49257a4b3287b7841922ecdff855fd80.jpg"

3. Restart your simulator to see the new files.

Thanh Lam
  • 696
  • 5
  • 11
1

The simplest solution is to simply sign into iCloud on the simulator then use that to transfer any files in the drive, including photos.

prolfe
  • 1,354
  • 12
  • 16
1

With iOS 11 and Xcode 9, just drag and drop photos to the Simulator. It will automatically import them in the Library app. Very easy!

aramusss
  • 2,391
  • 20
  • 30
0
  1. Ensure the device is running.

  2. Execute the following in terminal:

open ~/Library/Developer/CoreSimulator/Devices/$(xcrun simctl list | grep Booted | grep -Eo '[a-zA-Z0-9]*-[a-zA-Z0-9]*-[a-zA-Z0-9]*-[a-zA-Z0-9]*-[a-zA-Z0-9]*')/data/Media/DCIM

Further regex ref @ https://regex101.com/r/tY951n/3

Anand Rockzz
  • 6,072
  • 5
  • 64
  • 71