본문 바로가기

iOS/WWDC

[WWDC 2019] iOS 시뮬레이터 최대한 활용하기! - xcrun simctl (2/2)

WWDC 2019 Getting the Most Out of Simulator 를 정리한 포스트입니다.

더 자세한 내용을 원하시면 위 링크를 참조하시길 바랍니다.

 

iOS 시뮬레이터 최대한 활용하기! - Simulator (1/2)

iOS 시뮬레이터 최대한 활용하기! - xcrun simctl (2/2)

도움말

xcrun simctl help

 

xcrun simctl help

 

...더보기

 

usage: simctl [--set ] [--profiles ]  ...
       simctl help [subcommand]
Command line utility to control the Simulator

For subcommands that require a  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.
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

 

 

사용 가능한 장치, 장치 유형, 런타임 또는 장치 나열

xcrun simctl list

 

xcrun simctl list

 

 

...더보기
== Device Types ==
iPhone 4s (com.apple.CoreSimulator.SimDeviceType.iPhone-4s)
iPhone 5 (com.apple.CoreSimulator.SimDeviceType.iPhone-5)
iPhone 5s (com.apple.CoreSimulator.SimDeviceType.iPhone-5s)

== Runtimes ==
iOS 10.3 (10.3.1 - 14E8301) - com.apple.CoreSimulator.SimRuntime.iOS-10-3
iOS 12.0 (12.0 - 16A366) - com.apple.CoreSimulator.SimRuntime.iOS-12-0
iOS 13.0 (13.0 - 17A577) - com.apple.CoreSimulator.SimRuntime.iOS-13-0

== Devices ==
-- iOS 10.3 --
-- iOS 12.0 --
-- iOS 13.0 --
    iPhone 6s Plus (8B9EFF78-A757-4CF2-893B-B522F2C658B6) (Shutdown)
    iPhone 8 (FE309801-1DDD-4263-882A-AFDDAC753B12) (Shutdown)
    iPhone 8 Plus (80250E89-14BF-4A1B-9E31-106C5138246C) (Shutdown)

 

 xcrun simctl list devices "iPhone X" --json

 

 xcrun simctl list devices "iPhone X" --json

 

나의 디바이스에서 "iPhone X" 만 json 포맷으로 출력합니다.

 

...더보기
'== Devices ==
-- iOS 10.3 --
-- iOS 12.0 --
-- iOS 13.0 --
-- tvOS 12.2 --
-- tvOS 13.0 --
-- watchOS 5.0 --
-- watchOS 6.0 --
-- Unavailable: com.apple.CoreSimulator.SimRuntime.iOS-12-2 --
    iPhone Xʀ (48BBB2F0-E3B0-45D8-B019-DA36EA0A345D) (Shutdown) (unavailable, runtime profile not found)
-- Unavailable: com.apple.CoreSimulator.SimRuntime.iOS-12-4 --
    iPhone X (245293D4-443A-4AC5-B8EA-659C3C35E265) (Shutdown) (unavailable, runtime profile not found)
    iPhone Xs (1138B21E-B334-4648-81DE-593DC84AAF50) (Shutdown) (unavailable, runtime profile not found)
    iPhone Xs Max (EEEB4743-7F6A-4B97-A056-9F9819070747) (Shutdown) (unavailable, runtime profile not found)
    iPhone Xʀ (F856C1B3-B593-4387-9086-35DC494DDA36) (Shutdown) (unavailable, runtime profile not found)

 xcrun simctl list devices "iPhone X"  --json
{
  "devices" : {
    "com.apple.CoreSimulator.SimRuntime.iOS-12-0" : [

    ],
    "com.apple.CoreSimulator.SimRuntime.watchOS-6-0" : [

    ],
    "com.apple.CoreSimulator.SimRuntime.tvOS-12-2" : [

    ],
    "com.apple.CoreSimulator.SimRuntime.tvOS-13-0" : [

    ],
    "com.apple.CoreSimulator.SimRuntime.iOS-12-2" : [
      {
        "state" : "Shutdown",
        "isAvailable" : false,
        "name" : "iPhone Xʀ",
        "udid" : "48BBB2F0-E3B0-45D8-B019-DA36EA0A345D",
        "availabilityError" : "runtime profile not found"
      }
    ],
    "com.apple.CoreSimulator.SimRuntime.iOS-12-4" : [
      {
        "state" : "Shutdown",
        "isAvailable" : false,
        "name" : "iPhone X",
        "udid" : "245293D4-443A-4AC5-B8EA-659C3C35E265",
        "availabilityError" : "runtime profile not found"
      },
      {
        "state" : "Shutdown",
        "isAvailable" : false,
        "name" : "iPhone Xs",
        "udid" : "1138B21E-B334-4648-81DE-593DC84AAF50",
        "availabilityError" : "runtime profile not found"
      },
      {
        "state" : "Shutdown",
        "isAvailable" : false,
        "name" : "iPhone Xs Max",
        "udid" : "EEEB4743-7F6A-4B97-A056-9F9819070747",
        "availabilityError" : "runtime profile not found"
      },
      {
        "state" : "Shutdown",
        "isAvailable" : false,
        "name" : "iPhone Xʀ",
        "udid" : "F856C1B3-B593-4387-9086-35DC494DDA36",
        "availabilityError" : "runtime profile not found"
      }
    ],
    "com.apple.CoreSimulator.SimRuntime.iOS-13-0" : [

    ],
    "com.apple.CoreSimulator.SimRuntime.watchOS-5-0" : [

    ],
    "com.apple.CoreSimulator.SimRuntime.iOS-10-3" : [

    ]
  }
}



 

디바이스 생성

 

xcrun simctl create <Name> <DeviceType> <Runtime>

 

xcrun simctl create "Test Watch" "Apple Watch Series 4 - 44mm" watchOS6.0

EF552196-8E42-4722-87C6-8EABE1858D7D

 

 

Spawn

 

xcrun simctl spawn <Device> <Command> <Argments>

 

 

com.example.app 의 Database 를 초기화합니다.

 

xcrun simctl spawn booted defaults write com.example.app ResetDatabase -bool YES

 

log stream 유틸리티를 실행할 수도 있습니다.

 

xcrun simctl spawn booted log stream --predicate 'senderImagePath CONTAINS "nsurlsessiond"'

 

senderImagePath: The full path of the library, framework, kernel exten- sion, or mach-o image, that originated the event.

nsurlsessiond: iCloud가 컴퓨터와 iCloud 서버간에 iCloud Drive / 사진 / 연락처 등을 동기화하는 데 사용하는 프로세스입니다

 

senderImagePath 에서 nsurlsessiond 의 이름이 포함된 로그를 출력하는 명령입니다. 

 

자세한 log stream 명령어는 여기에서 확인할 수 있습니다.

 

diagnose

 

xcrun simctl diagnose -l

 

-l 옵션은 경고를 스킵합니다.

 

디스크의 로그뿐만 아니라 문제를 추적하는 데 유용한 임시 로깅 및 덤프 시스템 상태를 거치고 수집합니다.

 

 테스트 실패 또는 어떤 종류의 문제가 즉시 진단, 제어 진단을 캡처하는 경우 자동화 시스템에서 실행하는 것이 좋습니다.

 

 

Launch

 

xcrun simctl launch --console-pty booted com.apple.example -MyDefaultKey YES

 

launch는 앱을 실행합니다. 

 

--console-pty 는 std input, output, err 를 console 에 출력합니다.

 

User default 값을 MyDefaultKey Yes로 설정합니다.

 

Clone

 

xcrun simctl clone <device> <clone name>

 

자동화, 테스트, 실험에 사용할 수있는 매우 강력한 명령입니다.

테스트를 하면서 해당 사본을 실행하고 실험을 수행 한 다음 완료되면 버릴 수 있습니다.

 

그외 명령어

xcrun simctl boot <device>
xcrun simctl shutdown <device>
xcrun simctl delete <device>
xcrun simctl pair <watch> <phone>
xcrun simctl addmedia <device> <file1> <file2>
xcrun simctl get_app_container <device> <bundle id> <type>
xcrun simctl install <device> <example.app>
xcrun simctl io  screenshot <device> <output.png>

 

다음으로 Metal에 대해서 설명이 나오지만 충분한 Metal 에 대해 이해가 부족합니다 ㅠㅠ

그래서 다음 기회가 된다면 진행하겠습니다.

 

 

참고:

https://www.manpagez.com/man/1/log/

https://medium.com/xcblog/simctl-control-ios-simulators-from-command-line-78b9006a20dc

https://developer.apple.com/videos/play/wwdc2019/418