我试图使用UIImagePickerController与UIImagePickerControllerSourceTypePhotoLibrary,但它说,“没有照片”。模拟器从哪里获得图像?我应该在哪里复制图像,以便它们在模拟器中显示?


当前回答

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.

其他回答

从Xcode 6开始,你可以使用命令行工具xcrun simctl。

用法非常简单;要将照片添加到当前运行的模拟器中,您可以使用引导占位符。

xcrun simctl addmedia booted ./MyFile.jpg

要将它添加到任何其他模拟器,您可以使用它的设备id,可以通过运行xcrun simctl list找到它。

xcrun simctl addmedia E201E636-CE6C-11E5-AB30-625662870761 ./MyFile.jpg

如果你不能拖放你的文件,因为你遇到错误:

一个或多个媒体项导入失败::操作无法完成。(PHPhotosErrorDomain错误-1.)

将文件移动到Documents文件夹中,然后将它们拖到模拟器中。这将触发模拟器请求访问文件的权限。将它们放在下载文件夹中则不会。

我只是需要一些随机的图像进行测试,所以这就是我所做的。

我有世界上最简单的解决办法。只需在模拟器中打开Safari,转到谷歌图像(或您自己的web或Dropbox URL),查看图像,按住鼠标按钮2秒,你会看到“保存图像”-它会保存到照片库中。清洗并重复。

为此我编写了一个bash脚本。 检查链接[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

只需将图像拖到iPhone模拟器。