如何将图像添加到 iOS 模拟器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13441973/
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
How do I add images to the iOS Simulator
提问by wmichaelsen
I have xcode 4.5.1 and want to add photos to the iphone 6.0 simulator but cant find it. I have a folder named iphone simulator but it just contains 4.3.1. It may be because some months ago I drag almost everything in the application support to my extern hard drive to save some memory. Now when I drag it back it contains the 4.3.1 which I used before. Do I have to download something on new or what should I do? Thanks in advance!
我有 xcode 4.5.1 并且想将照片添加到 iphone 6.0 模拟器但找不到它。我有一个名为 iphone 模拟器的文件夹,但它只包含 4.3.1。这可能是因为几个月前我将应用程序支持中的几乎所有内容都拖到了我的外部硬盘驱动器中以节省一些内存。现在,当我将其拖回时,它包含我之前使用的 4.3.1。我必须下载新的东西还是我应该怎么做?提前致谢!
回答by Abizern
- Run the simulator
- Run Safari on the Simulator
- Drag a picture onto Safari running on the Simulator, this opens the image.
- Click and hold on the image, or tap on the share icon in the bottom tool bar.
- You'll get an alert asking if you want to store the image to your phone
- 运行模拟器
- 在模拟器上运行 Safari
- 将图片拖到在模拟器上运行的 Safari 上,这将打开图像。
- 单击并按住图像,或点击底部工具栏中的共享图标。
- 您会收到一条提醒,询问您是否要将图像存储到手机中
回答by Besi
There is a slightly faster approach than what Abizern described
有一种比 Abilern 描述的方法稍快的方法
- Open the Simulator
- Drag an image directly onto it (no need to launch Safari.app)
- Safari willl launch
- Long-Press the image and save it to the Simulators Camera Roll
- 打开模拟器
- 将图像直接拖到其上(无需启动 Safari.app)
- Safari 将启动
- 长按图像并将其保存到模拟器相机胶卷
Update for iOS9: Locally stored images can be dragged directly onto the simulator and don't have to be saved explicitly.
iOS9 更新:本地存储的图像可以直接拖到模拟器上,不必显式保存。
Please note that your images are stored here (6.1
matches the Simulator version):
请注意,您的图像存储在此处(6.1
与模拟器版本匹配):
~/Library/Application Suppport/iPhone Simulator/6.1/Media/DCIM/100APPLE
Unfortunately you can't just add images to that folder as they will be ignored because they're not in the image database of the Simulator. However you can get all the stored images via the Finder.
不幸的是,您不能只将图像添加到该文件夹中,因为它们将被忽略,因为它们不在模拟器的图像数据库中。但是,您可以通过 Finder 获取所有存储的图像。
回答by Gabriel.Massana
With Xcode 6is easier.
使用Xcode 6更容易。
1.- Drag and drop an Image to the Simulator and the image will appear directly in the native Photosapp.
1.- 将图像拖放到模拟器中,图像将直接出现在本机照片应用程序中。
回答by Mati Bot
With the drag and drop feature you will lose all the metadata of the photos.
使用拖放功能,您将丢失照片的所有元数据。
I've created a project that make it really easy to import assets to the simulator: MBAssetsImporter.
我创建了一个项目,可以非常轻松地将资产导入模拟器:MBAssetsImporter。
It enables you to import both videos and photos while preserving all the original metadata of the files.
它使您能够导入视频和照片,同时保留文件的所有原始元数据。
回答by George Brown
You can also now do this through the command line with smctl addmedia command.
您现在也可以使用 smctl addmedia 命令通过命令行执行此操作。
$ xcrun simctl addmedia
Usage: simctl addmedia <device> <path> [... <path>]
You can specify multiple files including a mix of photos and videos.
You can also specify multiple live photos by providing the photo and video files. They will automatically be discovered and imported correctly.
Note (you may not need to add xcrun in front of simctl depending on how command line tools are installed).
注意(根据命令行工具的安装方式,您可能不需要在 simctl 前面添加 xcrun)。
To find the correct device id, run simctl list devices
要找到正确的设备 ID,请运行 simctl list devices
$ xcrun simctl list devices
== Devices ==
-- iOS 10.2 --
iPhone 5 (D226CF12-6782-4D7D-9C00-2D662CF4022C) (Shutdown)
iPhone 5s (34E0E0F8-3429-4D91-B038-ECF4FD0F3311) (Shutdown)
iPhone 6 (9C772A68-34E3-4F3F-981C-543DE6D5D985) (Shutdown)
iPhone 6 Plus (7848A50E-BFB5-4F19-BB31-4A56CA78AA2C) (Shutdown)
iPhone 6s (12CF89BA-C8B2-4837-B4EB-FB24DFF1622C) (Shutdown)
iPhone 6s Plus (3EE6CA84-8F12-4A5E-A31D-EF4BF3CCBDB2) (Shutdown)
iPhone 7 (1EB3CE5D-849C-491C-9CAA-5E97B1BD89CE) (Booted)
iPhone 7 Plus (94FEFD36-6EFF-4762-BD21-79B1F958F6C6) (Shutdown)
iPhone SE (E8E8ECEB-34C0-44F0-B92E-57DCA91024F1) (Shutdown)
iPad Retina (0DA5BF39-3DC7-49B3-BE9B-2FA756FCA725) (Shutdown)
iPad Air (DAB9C2D3-8EBC-41DC-9C2D-0ECEC1D2FAE3) (Shutdown)
iPad Air 2 (1E2DA170-5C2E-413C-831B-FA65524643D3) (Shutdown)
iPad Pro (9.7 inch) (99F931A9-0708-4637-9294-6420DC7A149C) (Shutdown)
iPad Pro (12.9 inch) (08CD02EB-C44A-4183-961A-EED89FF1C225) (Shutdown)
-- tvOS 10.1 --
Apple TV 1080p (7EE393F2-C83E-467F-9802-3E5BFE7C2CA9) (Shutdown)
-- watchOS 3.1 --
Apple Watch - 38mm (B8969533-D7CD-462E-9E76-511C08E8CC8E) (Shutdown)
Apple Watch - 42mm (E16167D9-1007-438B-8812-CD97CE6ABECA) (Shutdown)
Apple Watch Series 2 - 38mm (F59C0BB1-B4D0-47DD-B927-1BFD78DD78C0) (Shutdown)
Apple Watch Series 2 - 42mm (7FE3AADD-94AB-46B9-A057-78F20F030999) (Shutdown)
So to add a video to my iPhone 7 simulator, I would use:
因此,要将视频添加到我的 iPhone 7 模拟器,我将使用:
$ xcrun simctl addmedia 1EB3CE5D-849C-491C-9CAA-5E97B1BD89CE <path to video>
回答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,照片应用程序打开,并立即将所有拖入的照片添加到设备中。
回答by Donald Burr
It's simple. Just goto photos in your iPhone simulator and drag images from your location (where the images Eg.Desktop) to IphoneSimulator. It add these picture in camera album.
这很简单。只需转到 iPhone 模拟器中的照片,然后将图像从您的位置(图像 Eg.Desktop 所在的位置)拖到 IphoneSimulator。它将这些图片添加到相册中。
回答by chetstone
Another easy way, in High Sierra with XCode 10, with your simulator running, select your photo in Photos, go the Share menu and select "Simulator".
另一种简单的方法是,在带有 XCode 10 的 High Sierra 中,在模拟器运行的情况下,在“照片”中选择您的照片,转到“共享”菜单并选择“模拟器”。
Voilá!
瞧!