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


当前回答

为此我编写了一个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

其他回答

从iOS 8开始,你只需将所有照片拖到模拟器窗口,它们就会自动保存到相机胶卷上。你可以想做多少就做多少。

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


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

注意-虽然这是有效的,并且工作,我认为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.0中,我们添加了将图像拖放到iOS模拟器中的功能。您可以将一堆图像拖到窗口中,它们应该被导入到该模拟设备的照片卷轴中。您还可以使用simctl命令行工具完成此操作。xrun simctl addphoto

方法1(最简单的方法):如果你的图像在Mac上

您可以将图像从Mac上的Finder拖到模拟器,它就会保存到“已保存的照片”相册中。

方法2:如果它在任何URL

将图片从网页保存到“照片”应用程序

将指针放在要保存的图像上,并按住鼠标按钮或触摸板。 当菜单出现时,单击Save Image将图像保存到iOS模拟器中的Photos应用程序中。 图片被保存到“照片”应用程序的“已保存照片”相册中。

以防有人在模拟器中寻找关于复制和粘贴的苹果文档。

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

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