iOS Simulators を CLI で操作する

xcrun simctl

ターミナル上で xcrun simctl を使って、Simulator の作成、起動、停止、削除等が行える。

list

マシン上にあるシミュレータのデバイス情報を一覧する。

xcrun simctl list

下記のように表示される。

== Device Types ==
...
iPhone Xs (com.apple.CoreSimulator.SimDeviceType.iPhone-XS)
iPhone Xs Max (com.apple.CoreSimulator.SimDeviceType.iPhone-XS-Max)
iPhone Xʀ (com.apple.CoreSimulator.SimDeviceType.iPhone-XR)
iPhone 11 (com.apple.CoreSimulator.SimDeviceType.iPhone-11)
iPhone 11 Pro (com.apple.CoreSimulator.SimDeviceType.iPhone-11-Pro)
iPhone 11 Pro Max (com.apple.CoreSimulator.SimDeviceType.iPhone-11-Pro-Max)

== Runtimes ==
iOS 13.3 (13.3 - 17C45) - com.apple.CoreSimulator.SimRuntime.iOS-13-3
tvOS 13.3 (13.3 - 17K446) - com.apple.CoreSimulator.SimRuntime.tvOS-13-3

== Devices ==
-- iOS 13.3 --
    iPhone 8 (720065F5-64E0-4A4D-8C03-5F63C6B4DCD5) (Shutdown)
    iPhone 8 Plus (9B24700B-74B9-40CF-B3B1-7860DDA0D150) (Shutdown)
    iPhone 11 (F8D133DB-F5C1-49B7-895F-530293A86EC3) (Shutdown)
    iPhone 11 Pro (505672AC-62B4-4B7B-BEFE-38EB984966FD) (Shutdown)
    iPhone 11 Pro Max (3EC97701-9372-4667-B5E3-D24BB2C57393) (Booted)
    iPad Pro (11-inch) (D4DCE5AF-8F36-485D-93F2-4D2CA9ADD29A) (Shutdown)
    iPad Pro (12.9-inch) (3rd generation) (18B1984A-F910-4BFC-98B0-0661C9C2B120) (Shutdown)
    iPad Air (3rd generation) (6C9D75DC-9A1D-4ADA-80C8-B8D3BDC08E1E) (Shutdown)

この中で、Devices に記載されている UUID を、後のコマンドで使用するのでメモしておく。

boot

xcrun simctl boot 3EC97701-9372-4667-B5E3-D24BB2C57393

shutdown

xcrun simctl shutdown 3EC97701-9372-4667-B5E3-D24BB2C57393

or

xcrun simctl shutdown booted

screencast

xcrun simctl io booted recordVideo ./screen_cast.mp4

screenshot

xcrun simctl io booted screenshot ./screenshot.png

or

xcrun simctl io booted screenshot ./screenshot.jpg

listapps

インストールされているアプリ一覧を取得できる。

xcrun simctl listapps booted

path of app

listapps した後、パスが分かるので中身を見られる。
中で SQLite を使っている場合などは直接確認したりできる。

xcrun simctl get_app_container booted <bundle identifier> data

other subcommands

その他のコマンド一覧。

Subcommands:
        create              Create a new device.
        clone               Clone an existing device.
        upgrade             Upgrade a device to a newer runtime.
        delete              Delete spcified devices, unavailable devices, or all devices.
        pair                Create a new watch and phone pair.
        unpair              Unpair a watch and phone pair.
        pair_activate       Set a given pair as active.
        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.
        addmedia            Add photos, live photos, videos, or contacts to the library of a device.
        install             Install an app on a device.
        uninstall           Uninstall an app from a device.
        get_app_container   Print the path of the installed app's container
        launch              Launch an application by identifier on a device.
        terminate           Terminate an application by identifier on a device.
        spawn               Spawn a process by executing a given executable on a device.
        list                List available devices, device types, runtimes, or device pairs.
        icloud_sync         Trigger iCloud sync on a device.
        pbsync              Sync the pasteboard content from one pasteboard to another.
        pbcopy              Copy standard input onto the device pasteboard.
        pbpaste             Print the contents of the device's pasteboard to standard output.
        help                Prints the usage for a given subcommand.
        io                  Set up a device IO operation.
        diagnose            Collect diagnostic information and logs.
        logverbose          enable or disable verbose logging for a device
        status_bar          Set or clear status bar overrides

Flutter で開発していると XCode 立ち上げたくはないし、 cli で操作できるのは色々便利ですね。

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です