Skip to content

Commit 2531708

Browse files
authored
Merge pull request #43 from joeblau/chore/iphone-deploy-command
chore: add paired iPhone deploy command
2 parents ba34510 + 2559292 commit 2531708

3 files changed

Lines changed: 77 additions & 0 deletions

File tree

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,18 @@ xcodebuild \
5454
build
5555
```
5656

57+
## Deploy to a paired iPhone
58+
59+
With one paired physical iPhone connected and unlocked, build, install, and
60+
launch the app with:
61+
62+
```bash
63+
bun stream
64+
```
65+
66+
If more than one iPhone is available, select one explicitly with
67+
`STREAM_DEVICE_ID=<UDID> bun stream`.
68+
5769
## Configure a stream
5870

5971
Open Settings and choose the transport:

package.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"name": "stream-ios",
3+
"private": true,
4+
"scripts": {
5+
"stream": "zsh scripts/stream.zsh"
6+
}
7+
}

scripts/stream.zsh

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/bin/zsh
2+
3+
set -euo pipefail
4+
5+
if [[ -z "${STREAM_DEVICE_ID:-}" ]]; then
6+
typeset -a available_iphones
7+
available_iphones=("${(@f)$(xcrun devicectl list devices \
8+
--filter "properties.hardware.reality = 'physical' AND properties.hardware.deviceType = 'iPhone' AND properties.connection.pairingState = 'paired' AND properties.state.bootState = 'booted'" \
9+
--columns 'properties.hardware.udid' \
10+
--hide-default-columns \
11+
--hide-headers)}")
12+
if (( ${#available_iphones} != 1 )); then
13+
print -u2 "Expected one paired, unlocked physical iPhone; found ${#available_iphones}."
14+
print -u2 "Connect one device or run STREAM_DEVICE_ID=<UDID> bun stream."
15+
exit 1
16+
fi
17+
STREAM_DEVICE_ID="${available_iphones[1]}"
18+
fi
19+
readonly STREAM_DEVICE_ID
20+
readonly STREAM_DESTINATION="platform=iOS,id=${STREAM_DEVICE_ID}"
21+
readonly STREAM_DERIVED_DATA_PATH="build/device"
22+
readonly STREAM_APP_PATH="${STREAM_DERIVED_DATA_PATH}/Build/Products/Debug-iphoneos/Stream.app"
23+
readonly STREAM_BUNDLE_ID="com.joeblau.Stream"
24+
25+
if ! xcrun devicectl list devices \
26+
--filter "properties.hardware.udid = '${STREAM_DEVICE_ID}' AND properties.hardware.reality = 'physical' AND properties.hardware.deviceType = 'iPhone' AND properties.connection.pairingState = 'paired' AND properties.state.bootState = 'booted'" \
27+
--columns 'properties.hardware.udid' \
28+
--hide-default-columns \
29+
--hide-headers | grep -Fqx "${STREAM_DEVICE_ID}"; then
30+
print -u2 "The selected iPhone is unavailable. Unlock it and connect it to this Mac, then try again."
31+
exit 1
32+
fi
33+
34+
print "Building Stream for ${STREAM_DEVICE_ID}..."
35+
xcodebuild \
36+
-project Stream.xcodeproj \
37+
-scheme Stream \
38+
-configuration Debug \
39+
-destination "${STREAM_DESTINATION}" \
40+
-derivedDataPath "${STREAM_DERIVED_DATA_PATH}" \
41+
-allowProvisioningUpdates \
42+
build
43+
44+
if [[ ! -d "${STREAM_APP_PATH}" ]]; then
45+
print -u2 "Build succeeded, but ${STREAM_APP_PATH} was not found."
46+
exit 1
47+
fi
48+
49+
print "Installing Stream..."
50+
xcrun devicectl device install app \
51+
--device "${STREAM_DEVICE_ID}" \
52+
"${STREAM_APP_PATH}"
53+
54+
print "Launching Stream..."
55+
xcrun devicectl device process launch \
56+
--device "${STREAM_DEVICE_ID}" \
57+
--terminate-existing \
58+
"${STREAM_BUNDLE_ID}"

0 commit comments

Comments
 (0)