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


当前回答

在运行IOS 8.0的Iphone Simulation中添加图像甚至更容易。

将图像拖到模拟器 IOS打开照片应用程序,你的照片现在是你的收藏的一部分。

没有必要再使用Safari了

其他回答

只需拖放图像到iphone模拟器。浏览器将打开显示您的图像。 按下图像,直到你没有收到保存图像的选项。然后保存图像。 就是这样:)。你会看到你的图像在你的模拟器....的照片应用程序

将图像、视频等放到模拟器上的最简单方法是将它们从计算机拖放到模拟器上。这将导致模拟器打开照片应用程序并开始填充库。


如果您想要一个可编写脚本的方法,请继续阅读。

注意-虽然这是有效的,并且工作,我认为Koen下面的解决方案现在是一个更好的,因为它不需要重新启动模拟器。

通过到xCode->Devices,选择您的模拟器,并检查Identifier值来识别您的模拟器。或者,您可以确保模拟器正在运行,并运行以下命令获取设备ID xcrun simctl list | grep Booted

~ /图书馆/开发/ CoreSimulator /设备/(模拟器标识符)/数据/媒体/ DCIM / 100苹果

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).

你也可以在模拟器中通过点击并按住图片来添加safari中的照片。如果您将图像(或任何其他文件,如PDF)拖到模拟器,它将立即打开Safari并显示图像,因此这是一种非常简单的获取图像的方法。

对于iOS 8,如果不需要保留照片捕捉日期和位置,只需将照片文件放到模拟器中即可。

要保留照片元数据,请执行以下操作:

复制照片文件到:/Users/{USER}/Library/Developer/CoreSimulator/Devices/{UDID}/data/Media/DCIM/100Apple 删除(或重命名)文件夹:/Users/{USER}/Library/Developer/CoreSimulator/Devices/{UDID}/data/Media/photoData 重新启动模拟器

注意:您需要用您的用户名替换{USER},用模拟器的UDID替换{UDID}。要从终端找到模拟器的UDID,请运行“xcrun simctl list”。

最简单的解决方案是在模拟器上登录iCloud,然后使用iCloud传输驱动器中的任何文件,包括照片。

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.