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


当前回答

使用拖放功能,您将丢失照片的所有元数据。

我已经创建了一个项目,可以很容易地将资产导入模拟器:MBAssetsImporter。

它使您可以导入视频和照片,同时保留文件的所有原始元数据。

其他回答

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.

对于iOS 5.1,这将进一步更改为new path

~/库/应用程序支持/iPhone模拟器/5.1/媒体/DCIM/100APPLE

确保设备处于运行状态。 在终端执行以下命令:

open ~/Library/Developer/CoreSimulator/Devices/$(xcrun simctl list | grep Booted | grep - eo '[a-zA-Z0-9]*-[a-zA-Z0-9]*-[a-zA-Z0-9]*-[a-zA-Z0-9]*-[a-zA-Z0-9]*')/data/Media/DCIM

进一步的regex ref @ https://regex101.com/r/tY951n/3

如果你需要导入不止一、两张照片,那就看看我写的这篇文章。它描述了一种简单的方法来执行批量导入照片,适用于iOS 4.x。

对于iOS 7,我做了以下操作:

复制照片到这两个文件夹:

~/Library/Application Support/iPhone Simulator/6.1/Media/DCIM/100APPLE
~/Library/Application Support/iPhone Simulator/7.0/Media/DCIM/100APPLE

只删除这4个文件(以避免重新启动时重复):

~/Library/Application Support/iPhone Simulator/6.1/Media/PhotoData/Photos.sqlite-shm
~/Library/Application Support/iPhone Simulator/6.1/Media/PhotoData/Photos.sqlite-wal
~/Library/Application Support/iPhone Simulator/7.0/Media/PhotoData/Photos.sqlite-shm
~/Library/Application Support/iPhone Simulator/7.0/Media/PhotoData/Photos.sqlite-wal