KEMBAR78
Simulator customizing & testing for Xcode 9 | PDF
Simulator
Simulator
Tips & Tricks
CLI, simctl
Testing
Demo
Simulator allows you to rapidly prototype and
test builds of your app during the development process.
open -a Simulator
open /Applications/Xcode.app/Contents/Developer/Applications/Simulator.app/
open -a Simulator --args -CurrentDeviceUDID $UDID
sudo mkdir /AppleInternal
Allow Fullscreen Mode
Show Chrome UI Rects
$ xcrun simctl list
$ xcrun simctl list devicetypes
$ xcrun simctl list -j runtimes
$ xcrun simctl list devices | grep Booted
xcrun simctl list [-j | ——json] [devices|devicetypes|runtimes|pairs]
xcrun simctl delete <device> [… <device n>] | unavailable
$ xcrun simctl delete 1418D7BD-CD6E-4C8A-AF95-580680AD5B2A
Delete
$ cd /Library/Developer/CoreSimulator/Profiles/Runtimes
$ sudo rm -rf <iOS version>.simruntime
$ xcrun simctl delete unavailable
2.72 GB
$ xcrun simctl create 'Giftbott X'  <- name
com.apple.CoreSimulator.SimDeviceType.iPhone-X  <- device type id
com.apple.CoreSimulator.SimRuntime.iOS-11-1 <- runtime id
xcrun simctl create <name> <device type id> <runtime id>
$ xcrun simctl rename 9E7DEEE4-035D-4CBC-B468-61D4D62618E7 'mySimulator'
xcrun simctl rename <device> <name>
xcrun simctl clone <device> <new name>
$ xcrun simctl clone 9E7DEEE4-035D-4CBC-B468-61D4D62618E7 'iPhone SE clone'
$ xcrun simctl boot A08C8834-1547-4EBB-BD3E-06D3732830F7
xcrun simctl boot <device> [-disabledJob=<job>] [-disabledJob=<job>]
xcrun simctl shutdown <device> | all
Booted / Shutdown
$ xcrun simctl shutdown A08C8834-1547-4EBB-BD3E-06D3732830F7
$ xcrun simctl shutdown all
$ xcodebuild ~~~ —sdk iphonesimulator
$ xcrun simctl install booted [Build Path]/GiftbotSimulator.app
xcrun simctl install <device> <path>
xcrun simctl uninstall <device> <app identifier>
Uninstall
Install
$ xcrun simctl uninstall booted kr.giftbot.example.GiftbotSimulator
$ xcrun simctl launch booted kr.giftbot.example
$ xcrun simctl launch ——console booted kr.giftbot.example
$ xcrun simctl launch booted kr.giftbot.example -AppleLocale "en_US" 
-AppleLanguages "(ko)" -NSShowNonLocalizedStrings YES
$ xcrun simctl launch booted kr.giftbot.example -foo "['1', '2']" bar
xcrun simctl launch [-w | ——wait—for—debugger] [——console] [——stdout=<path>]
[——stderr=<path>] <device> <app identifier> [<argv 1> … <argv n>]
xcrun simctl terminate <device> <app identifier>
$ xcrun simctl terminate booted kr.giftbot.example
$ xcrun simctl erase A08C8834-1547-4EBB-BD3E-06D3732830F7
$ xcrun simctl erase all
// Unable to erase in Booted state
$ xcrun simctl shutdown <device> && xcrun simctl erase <device>
xcrun simctl erase <device> [… <device n>] | all
erase
screenshot [--type=<type>] [--display=<display>] <file or url>
$ xcrun simctl io booted screenshot ——type=jpeg image.jpeg
$ xcrun simctl io booted screenshot ——display=external image.png
recordVideo [--type=<type>] [--display=<display>] <file or url>
$ xcrun simctl io booted recordVideo ——type="mp4" SwiftKorea.mp4
$ xcrun simctl io 90D0D799-69BA-4800-8682-1533100CDD7B recordVideo sim.mp4
xcrun simctl io <device> <operation> <arguments>
$ xcrun simctl keyboard booted ko
$ xcrun simctl keyboard booted ja
xcrun simctl keyboard <device> <language>
Add
$ xcrun simctl openurl booted https://google.com/search?q=SwiftKorea
$ xcrun simctl openurl booted https://swiftkorea.github.io/meetup/2
xcrun simctl openurl <device> <URL>
xcrun simctl <addmedia | addphoto | addvideo> <device> <path> [… <path>]
$ xcrun simctl addmedia booted ~/image.jpeg
$ xcrun simctl addmedia booted ~/video.mp4 ~/image.png …
$ xcrun simctl addphoto booted ~/Desktop/image.jpeg
$ xcrun simctl addvideo booted ~/movie/video.mp4
addmedia
$ xcrun simctl listapps booted
$ xcrun simctl listapps booted | grep '"com.apple.*" = ' | grep -o '".*"'
$ xcrun simctl listapps booted | sed -n '1,/kr.giftbot/!p' | sed -n '1,14p'
xcrun simctl listapps <device>
$ xcrun simctl appinfo booted kr.giftbot.example.GiftbotSimulator
xcrun simctl appinfo <device> <bundle identifier>
$ xcrun simctl spawn booted log stream
$ xcrun simctl spawn booted log stream --type=activity 
--style=json —timeout=1m
$ xcrun simctl spawn booted log stream --predicate 'processID == 50854 and 
messageType == info'
$ xcrun simctl spawn booted log stream --predicate "eventMessage contains 
'Giftbot' and messageType == debug and eventType == logEvent"
$ xcrun simctl spawn booted log collect
xcrun simctl spawn [-w | --wait-for-debugger] [-s | --standalone] [-a <arch> |
--arch=<arch>] <device> <path to executable> [<argv 1> <argv 2> ... <argv n>]
bootstatus
darwinup
diagnose
get_app_container
getenv
icloud_sync
logverbose
monitor
notify_post
notify_get_state / notify_set_state
pair / unpair
pair_activate
pbinfo / pbsync
pbcopy / pbpaste
register / unregister
upgrade
$ xcrun simctl list devices
$ xcrun simctl list devices 
| sed -n '{ 1,/iOS 10/d; /iPhone 6s/p; }'
$ xcrun simctl list devices 
| sed -n '{ 1,/iOS 10/d; /iPhone 6s/p; }' 
| egrep -o '([A-Z0-9-]*){36}'
$ xcrun simctl list devices 
| sed -n '{ 1,/iOS 10/d; /iPhone 6s/p; }' 
| egrep -o '([A-Z0-9-]*){36}' 
| xargs -I udid xcrun simctl boot udid
$ xcrun simctl list devices 
| grep 'iPhone [8X]' 
| awk -F "[()]" '{ print $2 }' 
| xargs -I udid xcrun simctl shutdown udid
$ list=(`xcrun simctl list devices 
| awk '/iPhone/{ if ($2 > 7 && $2 != "SE") print $(NF-1) }' 
| cut -c 2-37`)
$ for udid in $list; do
xcrun simctl shutdown $udid
done
$ xcrun simctl list devices 
| grep -i 'iphone.*plus' 
| tail -n 4 
| grep -v Booted 
| awk -F "[()]" '{ print $2 }' 
| xargs -I udid xcrun simctl erase udid
$ xcrun simctl list devices 
| grep Shutdown 
| egrep -o '[A-Z0-9-]{36}' 
| tail -n 4 
| xargs -I udid xcrun simctl erase udid
Case 1. Localization
Case 4. Devices
Case 5. Network
Case 2. Arguments
Case 3. Configurations
Shutdown
List
Create / Clone
Boot
[ 1 ]
Shutdown
List
Create / Clone
Boot
Build
Install
Launch
Test
[ 1 ] [ 2 ]
Shutdown
List
Create / Clone
Boot
Build
Install
Launch
Test
Terminate
Shutdown
Erase / Delete
[ 1 ] [ 3 ][ 2 ]
[ Simulator 1 ] - English + Locale(US)
[ Simulator 2 ] - Korean
[ Simulator 3 ] - Japanese
[ Simulator 4 ] - Base + DoubleLocalizedString + RightToLeftWritingDirection
[ Simulator 1 ] - English + Locale(US)
[ Simulator 2 ] - Korean
[ Simulator 3 ] - Japanese
[ Simulator 4 ] - Base + DoubleLocalizedString + RightToLeftWritingDirection
$ xcrun simctl launch <device> <bundle id> [<argv 1> ...]
[ Simulator 1 ] - English + Locale(US)
[ Simulator 2 ] - Korean
[ Simulator 3 ] - Japanese
[ Simulator 4 ] - Base + DoubleLocalizedString + RightToLeftWritingDirection
$ xcrun simctl launch booted kr.giftbot.example [<argv 1> ...]
[ 1 ] -AppleLanguages "(en)" -AppleLocale "en_US"
[ 2 ] -AppleLanguages "(ko)"
[ 3 ] -AppleLanguages "(ja)"
[ 4 ] -NSDoubleLocalizedString YES -NSForceRightToLeftWritingDirection YES
$ xcrun simctl launch booted kr.giftbot.example foo bar -swift true
let args = ProcessInfo.processInfo.arguments
for (idx, arg) in args.enumerated() {
print("idx : (idx), argument : (arg)")
}
$ xcrun simctl launch booted kr.giftbot.example foo bar -swift true
let args = ProcessInfo.processInfo.arguments
for (idx, arg) in args.enumerated() {
print("idx : (idx), argument : (arg)")
}
$ xcrun simctl launch booted kr.giftbot.example foo bar -swift true
idx : 0, argument : <appPath>/<scheme>
idx : 1, argument : foo
idx : 2, argument : bar
idx : 3, argument : -swift
idx : 4, argument : true
-Argument => UserDefaults
let isSwift = UserDefaults.standard.bool(forKey: "swift")
print(isSwift) // true
-Argument => UserDefaults
let isSwift = UserDefaults.standard.bool(forKey: "swift")
print(isSwift) // true
-arr "( 'Swift', 'Korea', 'Giftbot', 'Simulator Customizing & Testing' )"
-dict "{ 'Swift'='Korea'; '2nd'='Meetup'; 'Hi'='Nice to meet you'; }"
-xml "<dict><key>foo</key><string>bar</string></dict>"
let arrArg = UserDefaults.standard.array(forKey: "arr")
let dictArg = UserDefaults.standard.dictionary(forKey: “dict")
let xmlArg = UserDefaults.standard.object(forKey: "xml")
$ xcodebuild
-project <project path>
—scheme <scheme>
-sdk iphonesimulator
-configuration < Debug / Beta / Release >
$ xcodebuild
-project [projectPath]
—scheme [scheme]
-sdk iphonesimulator
-configuration [ Debug / Beta / Release ]
$ xcrun simctl install booted 
[Build Path]/Build/[Configuration]-iphonesimulator/[App Name].app
$ xcodebuild
-project <project path>
—scheme <scheme>
-sdk iphonesimulator
-configuration < Debug / Beta / Release >
$ xcrun simctl install booted 
[Build Path]/Build/<configuration>-iphonesimulator/<app name>.app
$ xcodebuild
-project <project path>
—scheme <scheme>
-sdk iphonesimulator
-configuration < Debug / Beta / Release >
$ xcrun simctl install booted 
[Build Path]/Build/<configuration>-iphonesimulator/<app name>.app
$ xcrun simctl launch <device> <bundle identifier>
xcrun simctl list devices | egrep ~ blah blah ~
Simulator customizing & testing for Xcode 9
Simulator customizing & testing for Xcode 9
Simulator customizing & testing for Xcode 9
Simulator customizing & testing for Xcode 9
Simulator customizing & testing for Xcode 9
Simulator customizing & testing for Xcode 9
Simulator customizing & testing for Xcode 9
Simulator customizing & testing for Xcode 9
Simulator customizing & testing for Xcode 9

Simulator customizing & testing for Xcode 9

  • 1.
  • 2.
    Simulator Tips & Tricks CLI,simctl Testing Demo
  • 3.
    Simulator allows youto rapidly prototype and test builds of your app during the development process.
  • 5.
    open -a Simulator open/Applications/Xcode.app/Contents/Developer/Applications/Simulator.app/ open -a Simulator --args -CurrentDeviceUDID $UDID
  • 10.
  • 11.
  • 14.
  • 22.
    $ xcrun simctllist $ xcrun simctl list devicetypes $ xcrun simctl list -j runtimes $ xcrun simctl list devices | grep Booted xcrun simctl list [-j | ——json] [devices|devicetypes|runtimes|pairs]
  • 24.
    xcrun simctl delete<device> [… <device n>] | unavailable $ xcrun simctl delete 1418D7BD-CD6E-4C8A-AF95-580680AD5B2A Delete
  • 25.
  • 26.
    $ xcrun simctldelete unavailable 2.72 GB
  • 28.
    $ xcrun simctlcreate 'Giftbott X' <- name com.apple.CoreSimulator.SimDeviceType.iPhone-X <- device type id com.apple.CoreSimulator.SimRuntime.iOS-11-1 <- runtime id xcrun simctl create <name> <device type id> <runtime id>
  • 30.
    $ xcrun simctlrename 9E7DEEE4-035D-4CBC-B468-61D4D62618E7 'mySimulator' xcrun simctl rename <device> <name> xcrun simctl clone <device> <new name> $ xcrun simctl clone 9E7DEEE4-035D-4CBC-B468-61D4D62618E7 'iPhone SE clone'
  • 31.
    $ xcrun simctlboot A08C8834-1547-4EBB-BD3E-06D3732830F7 xcrun simctl boot <device> [-disabledJob=<job>] [-disabledJob=<job>] xcrun simctl shutdown <device> | all Booted / Shutdown $ xcrun simctl shutdown A08C8834-1547-4EBB-BD3E-06D3732830F7 $ xcrun simctl shutdown all
  • 32.
    $ xcodebuild ~~~—sdk iphonesimulator $ xcrun simctl install booted [Build Path]/GiftbotSimulator.app xcrun simctl install <device> <path> xcrun simctl uninstall <device> <app identifier> Uninstall Install $ xcrun simctl uninstall booted kr.giftbot.example.GiftbotSimulator
  • 33.
    $ xcrun simctllaunch booted kr.giftbot.example $ xcrun simctl launch ——console booted kr.giftbot.example $ xcrun simctl launch booted kr.giftbot.example -AppleLocale "en_US" -AppleLanguages "(ko)" -NSShowNonLocalizedStrings YES $ xcrun simctl launch booted kr.giftbot.example -foo "['1', '2']" bar xcrun simctl launch [-w | ——wait—for—debugger] [——console] [——stdout=<path>] [——stderr=<path>] <device> <app identifier> [<argv 1> … <argv n>] xcrun simctl terminate <device> <app identifier> $ xcrun simctl terminate booted kr.giftbot.example
  • 34.
    $ xcrun simctlerase A08C8834-1547-4EBB-BD3E-06D3732830F7 $ xcrun simctl erase all // Unable to erase in Booted state $ xcrun simctl shutdown <device> && xcrun simctl erase <device> xcrun simctl erase <device> [… <device n>] | all erase
  • 35.
    screenshot [--type=<type>] [--display=<display>]<file or url> $ xcrun simctl io booted screenshot ——type=jpeg image.jpeg $ xcrun simctl io booted screenshot ——display=external image.png recordVideo [--type=<type>] [--display=<display>] <file or url> $ xcrun simctl io booted recordVideo ——type="mp4" SwiftKorea.mp4 $ xcrun simctl io 90D0D799-69BA-4800-8682-1533100CDD7B recordVideo sim.mp4 xcrun simctl io <device> <operation> <arguments>
  • 36.
    $ xcrun simctlkeyboard booted ko $ xcrun simctl keyboard booted ja xcrun simctl keyboard <device> <language> Add
  • 37.
    $ xcrun simctlopenurl booted https://google.com/search?q=SwiftKorea $ xcrun simctl openurl booted https://swiftkorea.github.io/meetup/2 xcrun simctl openurl <device> <URL>
  • 38.
    xcrun simctl <addmedia| addphoto | addvideo> <device> <path> [… <path>] $ xcrun simctl addmedia booted ~/image.jpeg $ xcrun simctl addmedia booted ~/video.mp4 ~/image.png … $ xcrun simctl addphoto booted ~/Desktop/image.jpeg $ xcrun simctl addvideo booted ~/movie/video.mp4 addmedia
  • 39.
    $ xcrun simctllistapps booted $ xcrun simctl listapps booted | grep '"com.apple.*" = ' | grep -o '".*"' $ xcrun simctl listapps booted | sed -n '1,/kr.giftbot/!p' | sed -n '1,14p' xcrun simctl listapps <device>
  • 40.
    $ xcrun simctlappinfo booted kr.giftbot.example.GiftbotSimulator xcrun simctl appinfo <device> <bundle identifier>
  • 41.
    $ xcrun simctlspawn booted log stream $ xcrun simctl spawn booted log stream --type=activity --style=json —timeout=1m $ xcrun simctl spawn booted log stream --predicate 'processID == 50854 and messageType == info' $ xcrun simctl spawn booted log stream --predicate "eventMessage contains 'Giftbot' and messageType == debug and eventType == logEvent" $ xcrun simctl spawn booted log collect xcrun simctl spawn [-w | --wait-for-debugger] [-s | --standalone] [-a <arch> | --arch=<arch>] <device> <path to executable> [<argv 1> <argv 2> ... <argv n>]
  • 42.
  • 44.
    $ xcrun simctllist devices
  • 45.
    $ xcrun simctllist devices | sed -n '{ 1,/iOS 10/d; /iPhone 6s/p; }'
  • 46.
    $ xcrun simctllist devices | sed -n '{ 1,/iOS 10/d; /iPhone 6s/p; }' | egrep -o '([A-Z0-9-]*){36}'
  • 47.
    $ xcrun simctllist devices | sed -n '{ 1,/iOS 10/d; /iPhone 6s/p; }' | egrep -o '([A-Z0-9-]*){36}' | xargs -I udid xcrun simctl boot udid
  • 49.
    $ xcrun simctllist devices | grep 'iPhone [8X]' | awk -F "[()]" '{ print $2 }' | xargs -I udid xcrun simctl shutdown udid $ list=(`xcrun simctl list devices | awk '/iPhone/{ if ($2 > 7 && $2 != "SE") print $(NF-1) }' | cut -c 2-37`) $ for udid in $list; do xcrun simctl shutdown $udid done
  • 50.
    $ xcrun simctllist devices | grep -i 'iphone.*plus' | tail -n 4 | grep -v Booted | awk -F "[()]" '{ print $2 }' | xargs -I udid xcrun simctl erase udid $ xcrun simctl list devices | grep Shutdown | egrep -o '[A-Z0-9-]{36}' | tail -n 4 | xargs -I udid xcrun simctl erase udid
  • 51.
    Case 1. Localization Case4. Devices Case 5. Network Case 2. Arguments Case 3. Configurations
  • 52.
  • 53.
  • 54.
  • 56.
    [ Simulator 1] - English + Locale(US) [ Simulator 2 ] - Korean [ Simulator 3 ] - Japanese [ Simulator 4 ] - Base + DoubleLocalizedString + RightToLeftWritingDirection
  • 57.
    [ Simulator 1] - English + Locale(US) [ Simulator 2 ] - Korean [ Simulator 3 ] - Japanese [ Simulator 4 ] - Base + DoubleLocalizedString + RightToLeftWritingDirection $ xcrun simctl launch <device> <bundle id> [<argv 1> ...]
  • 58.
    [ Simulator 1] - English + Locale(US) [ Simulator 2 ] - Korean [ Simulator 3 ] - Japanese [ Simulator 4 ] - Base + DoubleLocalizedString + RightToLeftWritingDirection $ xcrun simctl launch booted kr.giftbot.example [<argv 1> ...] [ 1 ] -AppleLanguages "(en)" -AppleLocale "en_US" [ 2 ] -AppleLanguages "(ko)" [ 3 ] -AppleLanguages "(ja)" [ 4 ] -NSDoubleLocalizedString YES -NSForceRightToLeftWritingDirection YES
  • 60.
    $ xcrun simctllaunch booted kr.giftbot.example foo bar -swift true
  • 61.
    let args =ProcessInfo.processInfo.arguments for (idx, arg) in args.enumerated() { print("idx : (idx), argument : (arg)") } $ xcrun simctl launch booted kr.giftbot.example foo bar -swift true
  • 62.
    let args =ProcessInfo.processInfo.arguments for (idx, arg) in args.enumerated() { print("idx : (idx), argument : (arg)") } $ xcrun simctl launch booted kr.giftbot.example foo bar -swift true idx : 0, argument : <appPath>/<scheme> idx : 1, argument : foo idx : 2, argument : bar idx : 3, argument : -swift idx : 4, argument : true
  • 63.
    -Argument => UserDefaults letisSwift = UserDefaults.standard.bool(forKey: "swift") print(isSwift) // true
  • 64.
    -Argument => UserDefaults letisSwift = UserDefaults.standard.bool(forKey: "swift") print(isSwift) // true -arr "( 'Swift', 'Korea', 'Giftbot', 'Simulator Customizing & Testing' )" -dict "{ 'Swift'='Korea'; '2nd'='Meetup'; 'Hi'='Nice to meet you'; }" -xml "<dict><key>foo</key><string>bar</string></dict>" let arrArg = UserDefaults.standard.array(forKey: "arr") let dictArg = UserDefaults.standard.dictionary(forKey: “dict") let xmlArg = UserDefaults.standard.object(forKey: "xml")
  • 69.
    $ xcodebuild -project <projectpath> —scheme <scheme> -sdk iphonesimulator -configuration < Debug / Beta / Release >
  • 70.
    $ xcodebuild -project [projectPath] —scheme[scheme] -sdk iphonesimulator -configuration [ Debug / Beta / Release ] $ xcrun simctl install booted [Build Path]/Build/[Configuration]-iphonesimulator/[App Name].app $ xcodebuild -project <project path> —scheme <scheme> -sdk iphonesimulator -configuration < Debug / Beta / Release > $ xcrun simctl install booted [Build Path]/Build/<configuration>-iphonesimulator/<app name>.app
  • 71.
    $ xcodebuild -project <projectpath> —scheme <scheme> -sdk iphonesimulator -configuration < Debug / Beta / Release > $ xcrun simctl install booted [Build Path]/Build/<configuration>-iphonesimulator/<app name>.app $ xcrun simctl launch <device> <bundle identifier>
  • 73.
    xcrun simctl listdevices | egrep ~ blah blah ~