Adding images to iPhone Simulator

2019-01-04 15:36发布

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?

30条回答
时光不老,我们不散
2楼-- · 2019-01-04 16:09

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.

查看更多
ら.Afraid
3楼-- · 2019-01-04 16:10

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
查看更多
我想做一个坏孩纸
4楼-- · 2019-01-04 16:10

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

查看更多
叼着烟拽天下
5楼-- · 2019-01-04 16:14

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

查看更多
霸刀☆藐视天下
6楼-- · 2019-01-04 16:14

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

查看更多
倾城 Initia
7楼-- · 2019-01-04 16:15

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

查看更多
登录 后发表回答