我试图使用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

其他回答

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

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

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

我只是偶然发现了如何在iOS模拟器上批量上传图像。(我只在6.1上确认过。)

备份文件夹: ~/库/应用程序支持/iPhone模拟器/6.1/媒体 复制所有图片到文件夹: ~/库/应用程序支持/iPhone模拟器/6.1/媒体/DCIM/100APPLE 移动或删除文件夹: ~/库/应用程序支持/iPhone模拟器/6.1/媒体/PhotoData 重启iOS模拟器 打开照片应用程序

模拟器将恢复100APPLE文件夹中的所有图像!

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

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 11和Xcode 9中,只需将照片拖放到模拟器中即可。它会自动在图书馆应用程序中导入它们。非常简单!