About Me

Patrick Quinn-Graham

Staff Engineer, Tokbox/Vonage

why are we here?

1. xcodebuild

# xcodebuild

build

your app, framework, ...

# xcodebuild test

test

ooh

# xcodebuild test -scheme SCHEME -destination DESTINATION

test on device

ooh-er!

# xcodebuild test -scheme SCHEME 
  -destination platform=iOS,name=DEVICE_NAME

# xcodebuild test -scheme SCHEME 
  -destination platform=iOS,id=SOME_DEVICE_UUID

# xcodebuild test -scheme SCHEME 
  -destination platform=macOS,arch=x86_64
# xcodebuild test -scheme SCHEME 
  -destination "platform=iOS Simulator,id=SIMULATOR_ID"

# xcodebuild test -scheme SCHEME 
  -destination "platform=iOS Simulator,name=iPhone SE,OS=12.0"

More Destinations

Read this

# xcodebuild test ... -workspace WORKSPACE

workspaces

# xcodebuild build-for-testing
# xcodebuild test-without-building

test without building every time

More on xcodebuild

Technical Note TN2339

2. IPAs

make an ipa

start with an archive

# xcodebuild archive -workspace WORKSPACE 
  -scheme SCHEME 
  -sdk iphoneos 
  -configuration AppStoreDistribution 
  -destination DESTINATION 
  -archivePath $PWD/build/archive.xcarchive

make an ipa

then export

# xcodebuild -exportArchive 
  -archivePath $PWD/build/archive.xcarchive 
  -exportOptionsPlist exportOptions.plist 
  -exportPath $PWD/build

make an ipa

...
    <key>method</key>
    <string>app-store</string>
    <key>teamID</key>
    <string>YOUR_TEN_CHARACTER_TEAM_ID</string>
...

upload an ipa to App Store Connect

# xcrun altool --upload-app -f MyApp.ipa 
  -u MY_USERNAME -p MY_PASSWORD

xcrun

Find and execute the named command line tool from the active developer directory.

xcode-select

Print the current Xcode:

# xcode-select -p

Set another:

# xcode-select --s /Path/To/Xcode.app/Contents/Developer

3. simctl

List things

Simulators

xcrun simctl list devices

List things

Device types

xcrun simctl list devicetypes

List things

Runtimes

xcrun simctl list runtimes

Create a simulator

# xcrun simctl create DevWorld
  com.apple.CoreSimulator.SimDeviceType.iPhone-X
  com.apple.CoreSimulator.SimRuntime.iOS-12-0

Get an app into your simulator

Install it

# xcrun simctl install SIMULATOR_ID /path/to/Your.app

And launch it

# xcrun simctl launch SIMULATOR_ID com.your.app

Or open a URL

xcrun simctl openurl SIMULATOR_ID x-your-app://

4. Patrick's weird tricks

running your app on a device?

not exactly

but you can cheat

spin the run loop!

func testRunner() {
    var dt = Date(timeIntervalSinceNow: 0.1)
    while true {
        RunLoop.current.run(mode: .default, before: dt)
        dt = Date(timeIntervalSinceNow: 0.1)
    }
}

the what loop?

Objective-C Macros

# xcodebuild build GCC_PREPROCESSOR_DEFINITIONS="MY_MACRO=@\"AWESOME\""
// and in objective-c:
-(void)awesomeFunction {
  NSLog(MY_MACRO);
}

Swift Flags

# xcodebuild ... OTHER_SWIFT_FLAGS="-D’COOL_FLAG’"
// your swift code
...
#if COOL_FLAG
  print(“WE Are Cool”)
#endif
...

Code signing

Code signing: Custom team

# xcodebuild DEVELOPMENT_TEAM=...

Code signing: Custom keychain

xcodebuild --keychain $PATH_TO_KEYCHAIN

"Load" a keychain

# security -v list-keychain -s path/to/keychain

"Unlock" a keychain

# security -v unlock-keychain -p $PASSWORD path/to/keychain

Change how long before you need to unlock the keychain again

# security -v set-chain-settings -t $TIMEOUT -l path/to/keychain

5. libimobiledevice

www.libimobiledevice.org

List devices

# idevice_id -l
d840b2e7fa04f99e0ee780d007433669b8bf9e87

Device info

# ideviceinfo -u $UUID -x -s

6. Grab bag

xcpretty

# gem install xcpretty

https://github.com/supermarin/xcpretty

fastlane

App automation done right

fastlane

code signing

certificates

fastlane

code signing

provisioning profiles

7. Questions?

thepatrick.io/talks.html

The end