Skip to content

Commit 60fa449

Browse files
committed
chore(examples): add iOS simulator selection script
1 parent a10467d commit 60fa449

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

examples/demo/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ For Android with multiple emulators, use the helper script to pick by AVD name:
3232
../run-android.sh
3333
```
3434

35+
For iOS with multiple simulators:
36+
37+
```bash
38+
../run-ios.sh
39+
```
40+
3541
Or specify a device directly:
3642

3743
```bash

examples/run-ios.sh

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
cd "$(dirname "$0")/demo"
5+
6+
ids=()
7+
names=()
8+
9+
while IFS='|' read -r id name; do
10+
ids+=("$id")
11+
names+=("$name")
12+
done < <(xcrun simctl list devices booted -j \
13+
| python3 -c "
14+
import json, sys
15+
data = json.load(sys.stdin)
16+
for runtime, devs in data.get('devices', {}).items():
17+
for d in devs:
18+
if d.get('state') == 'Booted':
19+
print(d['udid'] + '|' + d['name'])
20+
")
21+
22+
if [ ${#ids[@]} -eq 0 ]; then
23+
echo "No booted iOS simulators found."
24+
exit 1
25+
fi
26+
27+
if [ ${#ids[@]} -eq 1 ]; then
28+
echo "Using ${names[0]} (${ids[0]})"
29+
flutter run -d "${ids[0]}"
30+
exit 0
31+
fi
32+
33+
echo "Booted iOS simulators:"
34+
for i in "${!ids[@]}"; do
35+
echo " [$((i + 1))] ${names[$i]} (${ids[$i]})"
36+
done
37+
38+
printf "Choose [1-%d]: " "${#ids[@]}"
39+
read -r choice
40+
41+
if ! [[ "$choice" =~ ^[0-9]+$ ]] || [ "$choice" -lt 1 ] || [ "$choice" -gt ${#ids[@]} ]; then
42+
echo "Invalid choice."
43+
exit 1
44+
fi
45+
46+
idx=$((choice - 1))
47+
echo "Using ${names[$idx]} (${ids[$idx]})"
48+
flutter run -d "${ids[$idx]}"

0 commit comments

Comments
 (0)