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


当前回答

试试我做的这个应用。下载代码并在模拟器https://github.com/cristianbica/CBSimulatorSeed中运行

其他回答

对于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

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

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

它的简单。只需遵循以下步骤:

拖放图像到模拟器 现在图像打开到Safari浏览器(文件://…/ImageName)。点击并按住图像。 这将显示带有保存,取消选项的actionSheet(在iOS 7模拟器的情况下也复制)。 保存图像。图像被添加到Library中。

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


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

注意-虽然这是有效的,并且工作,我认为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并显示图像,因此这是一种非常简单的获取图像的方法。

只是告诉你:KONG的解决方案也适用于iOS 7测试版。

他的解决方案是:

将图像拖到模拟器,然后打开Safari(或在互联网上使用Safari浏览图像) 按住图像上的鼠标 当弹出窗口出现时,选择保存图像并享受;)