Clicky

iOS Dev Nugget 122 Importing Many Test Photos into iOS Simulator II

.

Need to run a code review on your codebase? Hire me

In #76: Importing Many Test Photos into iOS Simulator, I wrote about how you can built custom iOS apps to bulk load photos into the simulator. There is another way to do this. The simctl utility that comes with your Xcode installation lets you control the iOS simulator. Unless you have added it to your path, you'll have to use the full path to refer to it.

If you run it without any arguments, it will show you the commands available:

$ /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/simctl
Usage: simctl [--noxpc] [--set <set path>] <subcommand> ... | help [subcommand]
Command line utility to control the iOS Simulator

For subcommands that require a <device> argument, you may specify a device UDID
or the special "booted" string which will cause simctl to pick a booted device.
If multiple devices are booted when the "booted" device is selected, simctl
will choose one of them.

Subcommands:
        create        Create a new device.
        delete        Delete a device.
        erase         Erase a device's contents and settings.
        boot          Boot a device.
        shutdown      Shutdown a device.
        rename        Rename a device.
        getenv        Print an environment variable from a running device.
        openurl       Open a URL in a device.
        addphoto      Add a photo to the photo library of a device.
        install       Install an app on a device.
        uninstall     Uninstall an app from a device.
        launch        Launch an application by identifier on a device.
        spawn         Spawn a process on a device.
        list          List available devices, device types, or runtimes.
        notify_post   Post a darwin notification on a device.
        icloud_sync   Trigger iCloud sync on a device.
        help          Prints the usage for a given subcommand.

E.g. simctl list devices will list the simulators you have installed:

$ /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/simctl list devices

== Devices ==
-- iOS 7.0 --
-- iOS 7.1 --
    iPhone 4s-7.1 (CD87A880-494C-44C8-AF94-D316EB391BB6) (Shutdown)
    iPhone 5 (B937671C-5C95-4978-8425-C5EEA1849001) (Shutdown)
    iPhone 5s (F6CB1E39-A871-4044-92B7-3B1D92C64649) (Shutdown)
    iPad 2 (FF3F0C5E-FB6B-452C-BB6C-4226503EB287) (Shutdown)
    iPad Retina (6FE5DDD4-5899-44BD-B5BA-2E476800AC62) (Shutdown)
    iPad Air (402BBCCF-750F-4962-872C-74AC447E757D) (Shutdown)
-- iOS 8.1 --
    iPhone 4s (17484BC7-1DDE-4C9D-B678-A55ECAE86D50) (Shutdown)
    iPhone 5 (FD3A2930-DA6E-4316-B6AA-9EE8925D3780) (Shutdown)
    iPhone 5s (1979F6BD-0DC8-4B1D-A400-DEBB5B2A476A) (Booted)
    iPhone 6 Plus (6EB44A5F-ACCD-4751-B84C-C1904D18CE7D) (Shutdown)
    iPhone 6 (C9E7226E-7E34-470C-A76F-9EA153C15FFD) (Shutdown)
    iPad 2 (69447CBA-98F4-4624-A2D5-B521F966BC63) (Shutdown)
    iPad Retina (C90AA28D-405E-451A-B857-1CA0F52EC7DB) (Shutdown)
    iPad Air (4F8A5BF9-418B-43B0-B92C-80C8493653FF) (Shutdown)
    Resizable iPhone (E953192F-3EBA-432F-B6A9-B060BB5E599C) (Shutdown)
    Resizable iPad (F1D962E3-CF33-432A-8B57-18B48A02CA02) (Shutdown)

What we are interested here is the addphoto command, like so:

$ /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/simctl addphoto "1979F6BD-0DC8-4B1D-A400-DEBB5B2A476A" ~/Desktop/some-photo1.jpg

The simulator has to be running for addphoto to work. You can easily script this to bulk load multiple photos.

In fact, I built a command line tool to do it, see ios-simtool.


Your feedback is valuable: Do you want more nuggets like this?   Yes   or   No

.

.

Like this and want such iOS dev nuggets to be emailed to you, weekly?

Sign Me Up! or follow @iosdevnuggets on Twitter

.

View archives of past issues