Skip to content

Commit 8c77d9b

Browse files
committed
simplify build script
1 parent 7cc402f commit 8c77d9b

2 files changed

Lines changed: 17 additions & 106 deletions

File tree

examples/demo/Assets/Scripts/Editor/BuildScript.cs

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -68,29 +68,18 @@ public static void BuildAndroidEmulator()
6868

6969
/// <summary>
7070
/// Builds an Xcode project for the iOS Simulator.
71+
/// The OneSignal SDK post-processor automatically adds push capabilities,
72+
/// the NSE target, and CocoaPods entries during the build.
7173
/// </summary>
7274
public static void BuildiOSSimulator()
73-
{
74-
BuildiOS(iOSSdkVersion.SimulatorSDK);
75-
}
76-
77-
/// <summary>
78-
/// Builds an Xcode project for a physical iOS device.
79-
/// </summary>
80-
public static void BuildiOSDevice()
81-
{
82-
BuildiOS(iOSSdkVersion.DeviceSDK);
83-
}
84-
85-
private static void BuildiOS(iOSSdkVersion sdkVersion)
8675
{
8776
Directory.CreateDirectory(IOSOutputDir);
8877

8978
PlayerSettings.SetScriptingBackend(
9079
NamedBuildTarget.iOS,
9180
ScriptingImplementation.IL2CPP
9281
);
93-
PlayerSettings.iOS.sdkVersion = sdkVersion;
82+
PlayerSettings.iOS.sdkVersion = iOSSdkVersion.SimulatorSDK;
9483

9584
Debug.Log(
9685
$"[BuildScript] iOS sdk={PlayerSettings.iOS.sdkVersion} backend={PlayerSettings.GetScriptingBackend(NamedBuildTarget.iOS)}"

examples/demo/build_ios.sh

Lines changed: 14 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
#!/bin/sh
2-
# Build the OneSignal Unity demo for iOS simulator or device.
2+
# Build the OneSignal Unity demo for iOS simulator.
33
#
44
# Usage:
5-
# ./build_ios.sh [--device] [--no-install] [--install-only] [--open]
6-
#
7-
# By default targets the iOS Simulator. Pass --device to build for a
8-
# connected physical device instead.
5+
# ./build_ios.sh [--no-install] [--install-only] [--open]
96
set -eu
107

118
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
@@ -18,11 +15,9 @@ APP_BUNDLE_ID="com.onesignal.example"
1815
INSTALL=true
1916
SKIP_BUILD=false
2017
OPEN_XCODE=false
21-
DEVICE_BUILD=false
2218

2319
for arg in "$@"; do
2420
case "$arg" in
25-
--device) DEVICE_BUILD=true ;;
2621
--no-install) INSTALL=false ;;
2722
--install-only) SKIP_BUILD=true ;;
2823
--open) OPEN_XCODE=true; INSTALL=false; SKIP_BUILD=true ;;
@@ -58,63 +53,9 @@ for r,devs in d['devices'].items():
5853
SIM_NAME=$(echo "$LINE" | cut -d'|' -f2)
5954
}
6055

61-
pick_device() {
62-
LIST=$(python3 -c "
63-
import subprocess,json,sys,tempfile,os
64-
tmp = tempfile.mktemp(suffix='.json')
65-
subprocess.run(['xcrun','devicectl','list','devices','--json-output',tmp],
66-
capture_output=True, text=True)
67-
try:
68-
with open(tmp) as f: data = json.load(f)
69-
finally:
70-
try: os.unlink(tmp)
71-
except: pass
72-
for d in data.get('result',{}).get('devices',[]):
73-
identifier = d.get('identifier','')
74-
name = d.get('deviceProperties',{}).get('name','')
75-
platform = d.get('hardwareProperties',{}).get('platform','')
76-
if identifier and name and platform in ('iOS','iPadOS'):
77-
print(identifier + '|' + name)
78-
" 2>/dev/null || true)
79-
COUNT=$(printf '%s\n' "$LIST" | grep -c . || true)
80-
81-
[ "$COUNT" -eq 0 ] && echo "No connected devices found. Plug in a device or check Xcode." && exit 1
82-
[ "$COUNT" -eq 1 ] && DEV_UDID=$(echo "$LIST" | cut -d'|' -f1) && DEV_NAME=$(echo "$LIST" | cut -d'|' -f2) && return
83-
84-
echo "Multiple devices found — pick one:"
85-
i=1
86-
printf '%s\n' "$LIST" | while IFS='|' read -r UDID NAME; do
87-
printf " [%d] %s (%s)\n" "$i" "$NAME" "$UDID"
88-
i=$((i + 1))
89-
done
90-
printf "Choice [1-%d]: " "$COUNT"
91-
read -r CHOICE
92-
LINE=$(printf '%s\n' "$LIST" | sed -n "${CHOICE}p")
93-
[ -z "$LINE" ] && echo "Invalid choice." && exit 1
94-
DEV_UDID=$(echo "$LINE" | cut -d'|' -f1)
95-
DEV_NAME=$(echo "$LINE" | cut -d'|' -f2)
96-
}
97-
98-
TARGET_UDID=""
99-
TARGET_NAME=""
100-
101-
if [ "$INSTALL" = true ]; then
102-
if [ "$DEVICE_BUILD" = true ]; then
103-
DEV_UDID=""
104-
DEV_NAME=""
105-
pick_device
106-
TARGET_UDID="$DEV_UDID"
107-
TARGET_NAME="$DEV_NAME"
108-
else
109-
SIM_UDID=""
110-
SIM_NAME=""
111-
pick_simulator
112-
TARGET_UDID="$SIM_UDID"
113-
TARGET_NAME="$SIM_NAME"
114-
fi
115-
echo "Target: $TARGET_NAME ($TARGET_UDID)"
116-
echo ""
117-
fi
56+
SIM_UDID=""
57+
SIM_NAME=""
58+
[ "$INSTALL" = true ] && pick_simulator && echo "Target: $SIM_NAME ($SIM_UDID)" && echo ""
11859

11960
if [ "$OPEN_XCODE" = true ]; then
12061
WS="$XCODE_DIR/Unity-iPhone.xcworkspace"
@@ -130,20 +71,13 @@ if [ "$SKIP_BUILD" = true ]; then
13071
else
13172
[ ! -x "$UNITY" ] && echo "Unity not found at $UNITY — set UNITY_PATH" && exit 1
13273
mkdir -p "$XCODE_DIR"
133-
134-
if [ "$DEVICE_BUILD" = true ]; then
135-
BUILD_METHOD="BuildScript.BuildiOSDevice"
136-
echo "Generating Xcode project (IL2CPP / Device)..."
137-
else
138-
BUILD_METHOD="BuildScript.BuildiOSSimulator"
139-
echo "Generating Xcode project (IL2CPP / Simulator)..."
140-
fi
74+
echo "Generating Xcode project (IL2CPP / Simulator)..."
14175
echo "Log: $LOG"
14276
echo ""
14377

14478
START=$(date +%s)
14579
"$UNITY" -batchmode -nographics -quit -buildTarget iOS \
146-
-projectPath "$SCRIPT_DIR" -executeMethod "$BUILD_METHOD" \
80+
-projectPath "$SCRIPT_DIR" -executeMethod BuildScript.BuildiOSSimulator \
14781
-logFile "$LOG"
14882
ELAPSED=$(( $(date +%s) - START ))
14983

@@ -156,28 +90,22 @@ if [ -f "$XCODE_DIR/Podfile" ]; then
15690
(cd "$XCODE_DIR" && pod install --repo-update)
15791
fi
15892

159-
if [ "$INSTALL" = true ] && [ -n "$TARGET_UDID" ]; then
93+
if [ "$INSTALL" = true ] && [ -n "$SIM_UDID" ]; then
16094
echo ""
161-
echo "Building with xcodebuild..."
95+
echo "Building with xcodebuild for simulator..."
16296
WS="$XCODE_DIR/Unity-iPhone.xcworkspace"
16397
[ ! -d "$WS" ] && WS=""
16498

165-
if [ "$DEVICE_BUILD" = true ]; then
166-
DESTINATION="generic/platform=iOS"
167-
else
168-
DESTINATION="id=$TARGET_UDID"
169-
fi
170-
17199
BUILD_START=$(date +%s)
172100
if [ -n "$WS" ]; then
173101
xcodebuild -workspace "$WS" -scheme "$SCHEME" \
174-
-destination "$DESTINATION" \
102+
-destination "id=$SIM_UDID" \
175103
-derivedDataPath "$DERIVED" \
176104
-quiet \
177105
build
178106
else
179107
xcodebuild -project "$XCODE_DIR/Unity-iPhone.xcodeproj" -scheme "$SCHEME" \
180-
-destination "$DESTINATION" \
108+
-destination "id=$SIM_UDID" \
181109
-derivedDataPath "$DERIVED" \
182110
-quiet \
183111
build
@@ -188,13 +116,7 @@ if [ "$INSTALL" = true ] && [ -n "$TARGET_UDID" ]; then
188116
APP_PATH=$(find "$DERIVED" -name "*.app" -path "*/Build/Products/*" | head -1)
189117
[ -z "$APP_PATH" ] && echo "Could not find .app bundle in derived data." && exit 1
190118

191-
if [ "$DEVICE_BUILD" = true ]; then
192-
echo "Installing on $TARGET_NAME..."
193-
xcrun devicectl device install app --device "$TARGET_UDID" "$APP_PATH"
194-
xcrun devicectl device process launch --device "$TARGET_UDID" "$APP_BUNDLE_ID"
195-
else
196-
echo "Installing on $TARGET_NAME..."
197-
xcrun simctl install "$TARGET_UDID" "$APP_PATH"
198-
xcrun simctl launch "$TARGET_UDID" "$APP_BUNDLE_ID"
199-
fi
119+
echo "Installing on $SIM_NAME..."
120+
xcrun simctl install "$SIM_UDID" "$APP_PATH"
121+
xcrun simctl launch "$SIM_UDID" "$APP_BUNDLE_ID"
200122
fi

0 commit comments

Comments
 (0)