tags:

views:

2760

answers:

7

I have photos on my Mac that I would like to add to the iPhone Simulator to test my application.

In other words: how do I add photos to the iPhone Simulator?

Edit : What about iphone Simulator 4.0 ? iphone Simulator 3.0 & 4.0 both working differently.

Thanks in advance for helping me...

+5  A: 

Open the Window in mac where your images are stored.

Open your simulator another side.

Now drag your image from mac window to simulator,

simulator will open safari, and in a safari tab your image will be shown.

Tap & press down on image in simulator,

There will be message to "save image",

save image.

It will be added to your iPhone simulator.

Edit :

First just look at following image.

alt text

In iPhone simulator 4.0 ( iphone/iphone simulator ), itself it maintains a sqlite database for added images. So, if you want copy paste system - first make insert entries & then copy paste. That would be ridiculous way.

Ok. Let me explain simpler way of doing it.

  • open the finder in which you have bulk images that you want to add in simulator.
  • drag & drop first image into iphone simulator
  • on image - tap & hold for 1 second.
  • action sheet will appear - tap on save option
  • repeat same process for all images
  • this will do sqlite entries also.
  • now, open the /Users/YourUserName/Library/Application Support/iPhone Simulator/4.0
  • make a back up of Media directory. ( for example copy it & paste it on desktop )
  • when you reset your iphone simulator, all images will be gone
  • you need not to repeat all the process again, you have back up of it.
  • just copy & paste from back up to 4.0

alt text

sugar
+9  A: 

A more easy to understand version of sagar's answer:

Open a Finder window to where your images are stored and the iPhone Simulator. Then drag the images from the Finder window into the simulator. The simulator will open Safari with your image. Click and hold to save the image to the iPhone camera roll. You can now use those images as you normally would.

Darryl Hein
+9  A: 

I had the same question recently. The drop-the-photo-on-Safari approach works well enough if you're doing one at a time. For several images at once, I found a great blog post that explains where the simulator finds it's images.

The same poster links to a bash script to load a directory of images into the simulator. I now use this to reset my simulator's environment to a known good state as part of my build. That way, I can keep my images together with my code instead of depending on the state of the simulator's directory tree.

EDIT The original script was on a server that seems to be gone. I've pasted it here with the change needed for iPhone SDK 3.0. Credit for the script properly goes to the author of "Of Code and Men".

#!/bin/bash
simPath="$HOME/Library/Application Support/iPhone Simulator/User/Media/DCIM/100APPLE"
thmPath="$simPath/.MISC"

if [ -z "$1" ]; then
  echo usage: $0 "<folder>"
  exit 1
fi

if [ ! -d "$simPath" ]; then
  mkdir -p "$simPath"
  mkdir -p "$thmPath"
fi

# Find out which incremential number we're at currently.
index=1
for i in `ls $1/*.{jpg,png,gif,bmp} 2>/dev/null`; do
  while [ -f "$simPath/`printf IMG_%04d.JPG $index`" ]; do
    let index=$index+1
  done

  jpgName=`printf IMG_%04d.JPG $index`
  thmName=`printf IMG_%04d.THM $index`

  echo $i "->" $simPath/$jpgName

  sips -s format jpeg $i --out "$simPath/$jpgName" > /dev/null 2> /dev/null || continue
  sips -s format jpeg -z 96 96 $i --out "$thmPath/$thmName" > /dev/null 2> /dev/null || continue

  let index=$index+1
done
mtnygard
the code provided has one major problem.. files with spaces will not be handled correctly. Change the _for_ loop to: `for i in "$@"; do` And run it using `find ./photos -name "*.jpg" -exec ./load-photos.sh {} +` where your images are in _photos_ and the script above is saved as _load-photos.sh_
ohhorob
Alternatively, change the whole `for i in ...` line into: `find "$1" -iname "*\.jpg" 2>/dev/null | while read i; do` and the script will work as advertised.
Pascal
sugar
A: 

thanks, and a question... to transfer videos??

ghiboz
u should ask a new question for that.
sugar
A: 

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)

+1  A: 

Not working, none of them in iPhone Simulator 4.0

sicario
sugar
sicario
Is this any kind of answer ?
sugar
A: 

I've edited the script to create a structure that works with the iPhone 4.0.1 simulator. On my system I have subfolders for iphone simulator 3.2, 4.0 and 4.0.1. So I've kept the original output of the script and modified the structure as it needs to create a PhotoData folder for the thumbnails. After running the script I create sym links for the 3.2 4.0 and 4.0.1 simulator directories as follows:

ln -s $HOME/Library/Application\ Support/iPhone\ Simulator/User/Media/DCIM/ $HOME/Library/Application\ Support/iPhone\ Simulator/4.0.1/Media/DCIM
ln -s $HOME/Library/Application\ Support/iPhone\ Simulator/User/Media/PhotoData/ $HOME/Library/Application\ Support/iPhone\ Simulator/4.0.1/Media/PhotoData

future runs of the script will update all simulators. Here's the modified script:

#!/bin/bash

rootPath="$HOME/Library/Application Support/iPhone Simulator/User/Media"
relPath="100APPLE"
simPath="$rootPath/DCIM/$relPath"
thmPath="$rootPath/PhotoData/$relPath"

if [ -z "$1" ]; then
  echo usage: $0 "<folder>"
  exit 1
fi

if [ ! -d "$simPath" ]; then
  mkdir -p "$simPath"
  mkdir -p "$thmPath"
fi

echo "Finding pictures..."
# Find out which incremential number we're at currently.
index=1
for i in `ls $1/*.{JPG,jpg,png,gif,bmp} 2>/dev/null`; do
  echo "considering $i..."
  while [ -f "$simPath/`printf IMG_%04d.JPG $index`" ]; do
    let index=$index+1
  done

  jpgName=`printf IMG_%04d.JPG $index`
  thmName=`printf IMG_%04d.THM $index`

  echo $i "->" $simPath/$jpgName
  echo $i "->" $thmPath/$thmName

  sips -s format jpeg $i --out "$simPath/$jpgName" > /dev/null 2> /dev/null || continue
  sips -s format jpeg -z 96 96 $i --out "$thmPath/$thmName" > /dev/null 2> /dev/null || continue

  let index=$index+1
done
Cliff