How do I add images to the iOS Simulator

笑着哭i 提交于 2019-11-27 12:19:31
  1. Run the simulator
  2. Run Safari on the Simulator
  3. Drag a picture onto Safari running on the Simulator, this opens the image.
  4. Click and hold on the image, or tap on the share icon in the bottom tool bar.
  5. You'll get an alert asking if you want to store the image to your phone

There is a slightly faster approach than what Abizern described

  1. Open the Simulator
  2. Drag an image directly onto it (no need to launch Safari.app)
  3. Safari willl launch
  4. Long-Press the image and save it to the Simulators Camera Roll

Update for iOS9: Locally stored images can be dragged directly onto the simulator and don't have to be saved explicitly.

Please note that your images are stored here (6.1 matches the Simulator version):

~/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.

With Xcode 6 is easier.

1.- Drag and drop an Image to the Simulator and the image will appear directly in the native Photos app.

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.

It enables you to import both videos and photos while preserving all the original metadata of the files.

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 more photos onto the iOS Simulator window, and instead of opening Safari, the Photos app opens, and instantly adds all dragged-in photos to the device.

You can also now do this through the command line with smctl addmedia command.

$ 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).

To find the correct device id, run 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:

$ xcrun simctl addmedia 1EB3CE5D-849C-491C-9CAA-5E97B1BD89CE <path to video>

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.

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".

Voilá!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!