ios 将图像添加到 iPhone 模拟器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/468879/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Adding images to iPhone Simulator
提问by Vijayeta
I am trying to use UIImagePickerController
with UIImagePickerControllerSourceTypePhotoLibrary
, but it says, "No photos". Where does the simulator get the images from? Where should I copy the images so that they are displayed in the simulator?
我正在尝试使用UIImagePickerController
with UIImagePickerControllerSourceTypePhotoLibrary
,但它说“没有照片”。模拟器从哪里获取图像?我应该在哪里复制图像以便它们显示在模拟器中?
采纳答案by Airsource Ltd
The simplest way to get images onto the simulator is to drag and drop them. This will cause the Simulator to open the Photos app.
将图像放到模拟器上的最简单方法是拖放它们。这将导致模拟器打开照片应用程序。
If you want a scriptable method, read on.
如果您想要一个可编写脚本的方法,请继续阅读。
Note - while this is valid, and works, I think Koen's solution belowis now a better one, since it does not require rebooting the simulator.
注意 - 虽然这是有效的并且有效,但我认为下面的 Koen 解决方案现在是更好的解决方案,因为它不需要重新启动模拟器。
Identify your simulator by going to xCode->Devices, selecting your simulator, and checking the Identifier value.
通过转到 xCode->Devices,选择您的模拟器并检查 Identifier 值来识别您的模拟器。
Go to
去
~/Library/Developer/CoreSimulator/Devices/[Simulator Identifier]/data/Media/DCIM/100APPLE
~/Library/Developer/CoreSimulator/Devices/[Simulator Identifier]/data/Media/DCIM/100APPLE
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).
并添加 IMG_nnnn.THM 和 IMG_nnnn.JPG。然后你需要重置你的模拟器(硬件->重启)以让它注意到新的变化。它们是否不是 JPEG 并不重要 - 它们都可以是 PNG,但似乎它们都必须存在才能使其工作。如果 DCIM 尚不存在,您可能需要创建它,在这种情况下,您应该从 0001 开始 nnnn。JPG 文件是全尺寸版本,而 THM 文件是缩略图,大小为 75x75 像素。我写了一个脚本来做到这一点,但有一个更好地记录一个在这里(-link不再工作)。
You can also add photos from safari in the simulator, by Tapping and Holding on the image. If you drag an image (or any other file, like a PDF) to the simulator, it will immediately open Safari and display the image, so this is quite an easy way of getting images to it.
您还可以通过点击并按住图像在模拟器中添加来自 safari 的照片。如果您将图像(或任何其他文件,如 PDF)拖到模拟器中,它会立即打开 Safari 并显示图像,因此这是获取图像的一种非常简单的方法。
回答by KONG
Explain step by step of Airsource Ltd's answer for adding image to simulator:
逐步解释 Airsource Ltd 将图像添加到模拟器的答案:
- Drag it to simulator, then Safari opens (or browse to the Image in the internet using Safari)
- Hold your click on the image
- When the pop-up appears, choose Save Image and enjoy ;)
- 将其拖至模拟器,然后 Safari 打开(或使用 Safari 浏览互联网中的图像)
- 按住你的图片
- 当弹出窗口出现时,选择保存图像并享受 ;)
Update: for iOS Simulator 4.2, do these steps twice to get it work. Thanks kevboh
!
更新:对于 iOS Simulator 4.2,执行这些步骤两次以使其工作。谢谢kevboh
!
Update: This also works for iOS Simulator 6.1
更新:这也适用于 iOS Simulator 6.1
回答by user380427
3 Simple Steps
3个简单的步骤
- Drag & Drop image onto simulator
- this will open a browser with your image - Click & hold image
- this will open options - save image
- this will copy image onto simulator
- 将图像拖放到模拟器上
- 这将打开带有图像的浏览器 - 单击并按住图像
- 这将打开选项 - 保存图像
- 这会将图像复制到模拟器上
回答by Jeremy Huddleston Sequoia
With iOS 8.0, we added the ability to just drag and drop images into the iOS Simulator. You can drag a bunch of images into the window, and they should be imported into the photo reel for that simulated device. You can also do this with the simctl command line tool. 'xcrun simctl addphoto '
在 iOS 8.0 中,我们添加了将图像拖放到 iOS 模拟器中的功能。您可以将一堆图像拖到窗口中,然后将它们导入到该模拟设备的照片卷轴中。您也可以使用 simctl 命令行工具执行此操作。'xcrun simctl addphoto '
回答by Koen.
Since Xcode 6 you can use the command line tool xcrun simctl
.
从 Xcode 6 开始,您可以使用命令行工具xcrun simctl
。
Usage is very simple; to add a photo to the currently running simulator you use the booted
placeholder.
使用方法非常简单;要向当前运行的模拟器添加照片,请使用booted
占位符。
xcrun simctl addmedia booted ./MyFile.jpg
To add it to any other simulator, you use its device id, which can be found by running xcrun simctl list
.
要将其添加到任何其他模拟器,请使用其设备 ID,可以通过运行xcrun simctl list
.
xcrun simctl addmedia E201E636-CE6C-11E5-AB30-625662870761 ./MyFile.jpg
回答by Jayprakash Dubey
Its simple. Just follow these steps :
这很简单。只需按照以下步骤操作:
- Drag and drop image onto Simulator
- Now image opens into Safari browser (file://.../ImageName). Tap-and-hold on the Image.
This displays actionSheet with Save, Cancel option (Also copy in case of iOS 7 simulator).
Save the image. The image gets added into Library.
- 将图像拖放到模拟器上
- 现在图像在 Safari 浏览器中打开 (file://.../ImageName)。点击并按住图像。
这将显示带有保存、取消选项的 actionSheet(在 iOS 7 模拟器的情况下也复制)。
保存图像。图像被添加到库中。
回答by Arel
I just stumbled upon how to bulkupload images on the iOS Simulator. (I've only confirmed it on 6.1.)
我只是偶然发现了如何在 iOS 模拟器上批量上传图像。(我只在 6.1 上确认过。)
Backup the folder:
~/Library/Application Support/iPhone Simulator/6.1/Media
Copy all your images into the folder:
~/Library/Application Support/iPhone Simulator/6.1/Media/DCIM/100APPLE
Move or delete the folder:
~/Library/Application Support/iPhone Simulator/6.1/Media/PhotoData
Restart iOS Simulator
Open the Photosapp
备份文件夹:
~/Library/Application Support/iPhone Simulator/6.1/Media
将所有图像复制到文件夹中:
~/Library/Application Support/iPhone Simulator/6.1/Media/DCIM/100APPLE
移动或删除文件夹:
~/Library/Application Support/iPhone Simulator/6.1/Media/PhotoData
重启 iOS 模拟器
打开照片应用
The simulator will restore all the images from the 100APPLE folder!
模拟器将从 100APPLE 文件夹中恢复所有图像!
回答by user2966386
For iOS 7 I did the following:
对于 iOS 7,我执行了以下操作:
copy photos to these two folders:
将照片复制到这两个文件夹:
~/Library/Application Support/iPhone Simulator/6.1/Media/DCIM/100APPLE
~/Library/Application Support/iPhone Simulator/7.0/Media/DCIM/100APPLE
delete these 4 files only (to avoid duplicates on relaunch):
仅删除这 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
回答by Mihail Salari
Just drag images to the iPhone simulator.
只需将图像拖到 iPhone 模拟器即可。
回答by Donald Burr
This is MUCH easier with the new iOS Simulator that comes with Xcode 6+ (iOS Simulator 8.1 and above.) Now all you have to do is drag one or morephotos onto the iOS Simulator window, and instead of opening Safari, the Photos app opens, and instantly adds alldragged-in photos to the device.
使用 Xcode 6+(iOS 模拟器 8.1 及更高版本)附带的新 iOS 模拟器,这变得容易多了。现在您要做的就是将一张或多张照片拖到 iOS 模拟器窗口中,而不是打开 Safari,照片应用程序打开,并立即将所有拖入的照片添加到设备中。