How to import photos into the iPhone Simulator

by Robin Summerhill on September 1, 2010

One question that gets asked frequently in iPhone developer forums is, ‘How do I add photos to the Camera Roll in the iPhone Simulator?’ The most-quoted solution is to drag an image onto the simulator window. This will open it in Mobile Safari from where you can save it to the Camera Roll by tapping and holding on the image. This is fine if you just need one or two images, however, if you need to load a large number of photos into the simulator then this one-by-one approach is going to get very tired very quickly. We hit this problem while developing an app for a client that includes a custom photo browser and we needed to load 100s of photos during testing.

The Simulator

Other approaches involve copying image files directly into the Simulator under its Media directory at [home]/Library/Application Support/iPhone Simulator/4.x/Media. However, copying images directly into the Simulator can lead to problems with missing thumbnails or images just not appearing at all in the Photos app or Image Picker.

Our solution was to write an iPhone app designed to run in the Simulator that performs a bulk import of image files from disk. The app leverages iOS support for saving photos to the user’s Camera Roll, which ensures that thumbnails are generated correctly and the Photo database is updated.

The Image Importer app

OK, so it’s not pretty, but it does the job. All you need to do is download the Xcode project at the bottom of this article, build it and run it in the iPhone Simulator.

Once the app is running just follow the instructions. Copy images that you want to import into the folder shown (jpg or png). The default location is a folder called ‘iPhone Images’ under your Pictures folder but you can change this if needed. Click the ‘Import’ button and wait. All being well, your images should now appear correctly in the Photo app. They will also be available through the Image Picker API and the new ALAssetsLibrary API in iOS4.0.

We’d love to hear if you have found this article useful – leave a comment.

Update: Some people are seeing a ‘Data Unavailable’ error. To fix this choose “Reset Content and Settings…” from the iPhone Simulator menu.

If you are still receiving the same error after this then:

  1. Drag and drop an image onto the simulator to open it in Mobile Safari
  2. Click on the image and hold
  3. Choose “Save Image”
  4. Open the Photo app in the simulator to rebuild your photo library


Share and Enjoy:
  • Print
  • email
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Reddit
  • Twitter

{ 27 comments… read them below or add one }

Magi September 3, 2010 at 9:10 am

Very nice tool!!! thanks…
Just a little problem in the zip: the resource image “aptogo.png” was missing and the project didn’t build properly. I just removed it and all is working fine…
Cheers
magi

Reply

Robin Summerhill September 7, 2010 at 8:24 am

Hi Magi,

Glad you like the tool. I’ve updated the project to include the resource image. Thanks for pointing this out.

Reply

Caroline September 11, 2010 at 9:12 am

Thanks very much :) . I was getting the error “Data Unavailable” on the Import, but after I did iPhone Simulator > Reset Contents and Settings, it worked a treat.

Reply

Badisi September 23, 2010 at 4:45 am

Thanks for the sample.
Anyhow, it doesn’t work if there is no pictures in the library yet : “Data Unavailable” error
I had to drag and drop an image in the simulator, then click on it and hold, and finally choose “save image”
That creates a new library and after that everything worked well.

Reply

danno watts September 29, 2010 at 3:07 pm

thanks so much for writing this handy little utility! it really does help out a TON!

rocksteady,
danno~

Reply

mike October 20, 2010 at 9:00 am

doesn’t work. Data Unavailable error.

Reply

Robin Summerhill October 20, 2010 at 9:46 am

See the new update at the end of the article about how to fix this.

Reply

Myno December 7, 2010 at 3:11 am

Mahalo Robin, worked like a charm.

Reply

Mithun December 7, 2010 at 6:38 am

Hi Robin,
Great tool. Worked nice for me at the first try itself. Thanks

Reply

viktor January 10, 2011 at 5:36 pm

Thank you! It works, but path to the folder for import must be without white spaces:
iPhone Images -> iPhoneImages

Reply

Robin Summerhill March 4, 2011 at 7:51 am

Strange – it works with folders with space in for me!

Reply

David March 2, 2011 at 9:15 pm

I’m using the 4.2 SDK and I get the “Data Unavailable” error every time. I tried both resetting the settings and saving an image and still have the problem. Any other ideas? Thanks!

Reply

Robin Summerhill March 2, 2011 at 10:15 pm

You need to open the Photo app in the simulator once you have saved an image from Safari. You should see a progress bar with a message indicating that the photo library is being rebuilt. It should work after this.

Reply

David March 3, 2011 at 2:15 pm

That worked, thanks! This app was just what I needed!

Reply

David James March 10, 2011 at 8:49 am

Thanks so much for sharing this. I would have been fine with adding single images, but 4.2 isn’t playing nice. Your app works perfect. Thanks again.

Reply

Rama Krishna Chunduri March 11, 2011 at 3:32 am

I have a small idea to implement the same with IOS 3.x & may be for earlier too.
However some slight modification must help.
1. Ask user to run this app in simulator once and then exit.
2. Now ask him to navigate to /Library/Application Support/iPhone Simulator/x.x/
3. Now he have too look in all the directories for ImageImporter.app file.
4. Once he found he can copy all the picture files to documents folder.
5. The next time when opens the app you can just check for no.of.files in Documents directory and start process of importing from documents directory.
6.finally let him exit the app and start photos application.

So,that way you can give 2 downloadables for ios x.x & 4.x
This is just a suggestion, Im sorry if you have already tried this one.

Reply

Robin Summerhill March 11, 2011 at 8:26 am

Hi,

Not sure I follow you. The app works with iOS 3.x already. In fact the UIImageWriteToSavedPhotosAlbum function that is the key to saving photos into the camera roll on the simulator has been around since OS2.0.

Robin

Reply

balaji bal April 25, 2011 at 7:57 pm

Hi,
just a big thank you. Spared me a sleepless night.

Reply

Dave Bomberg May 29, 2011 at 5:15 pm

Thank you for the utility, works great. You might want to change the label that reads “Add images to this folder” to “Copy images FROM this folder”

Reply

Aaron Brown July 10, 2011 at 1:45 am

Thanks so much for this! For some reason saving through safari wasn’t working properly for me. This is an even better solution! BTW, I initially had the error of Data Unavailable and the “Reset Content and Settings” didn’t fix it. I removed the space in the directory path and change it in the path in the app and then it worked like a charm. Life saver :)

Reply

Ian Ferguson August 23, 2011 at 11:40 am

Very useful. Safari does not always save images correctly on the simulator. This app does the trick !!!

Reply

Dan August 25, 2011 at 6:26 pm

Thanks for the app!

As a follow up to the ‘data unavailable’ error, I spent 20 minutes wondering why it was happening and discovered it was because I had a model view open in Xcode.

As soon as I switched to a class view the problem ceased.

Reply

Nathan November 9, 2011 at 9:17 am

Many thanks!

Reply

Andy Riordan December 14, 2011 at 2:44 pm

I appreciate this tool, thanks!

Reply

Paul January 2, 2012 at 3:36 am

Very useful to import many photos in one go. Thanks a lot.

Reply

Glen March 12, 2012 at 11:18 pm

Oh so useful. Thanks heaps for sharing!

Reply

Dan April 2, 2012 at 6:13 am

Nice one – great tool!

Reply

Leave a Comment

Previous post:

Next post: