forked from jsnbuchanan/crowd-funder-for-time-pwa
Add iOS support for custom API IP configuration
Extend custom API IP feature to iOS platform with platform-appropriate defaults: - Android: Defaults to 10.0.2.2 for emulator, custom IP for physical devices - iOS: Uses localhost for simulator, custom IP for physical devices - Added npm scripts for iOS custom IP builds (dev:custom, test:custom) - Updated documentation to cover both platforms with examples - Consistent --api-ip parameter across Android and iOS build scripts Usage: ./scripts/build-ios.sh --dev # Default localhost ./scripts/build-ios.sh --dev --api-ip 192.168.1.100 # Custom IP
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
# Android Custom API IP Configuration
|
# Mobile Custom API IP Configuration
|
||||||
|
|
||||||
**Author**: Matthew Raymer
|
**Author**: Matthew Raymer
|
||||||
**Date**: 2025-01-27
|
**Date**: 2025-01-27
|
||||||
@@ -10,61 +10,85 @@ When deploying TimeSafari to physical Android devices during development, you ma
|
|||||||
|
|
||||||
## Problem
|
## Problem
|
||||||
|
|
||||||
During Android development:
|
During mobile development:
|
||||||
- **Emulator**: Uses `10.0.2.2:3000` to access host machine's localhost (default)
|
- **Android Emulator**: Uses `10.0.2.2:3000` to access host machine's localhost (Android emulator default)
|
||||||
- **Physical Device**: Cannot access `localhost` or `10.0.2.2` - needs actual IP address
|
- **iOS Simulator**: Uses `localhost:3000` to access host machine's localhost (iOS simulator default)
|
||||||
|
- **Physical Devices**: Cannot access `localhost` or `10.0.2.2` - needs actual IP address for network access
|
||||||
|
|
||||||
## Solution
|
## Solution
|
||||||
|
|
||||||
The Android build system defaults to `10.0.2.2:3000` for emulator development and supports specifying a custom IP address for the claim API server when building for physical devices.
|
The mobile build system uses platform-appropriate defaults and supports specifying a custom IP address for the claim API server when building for physical devices:
|
||||||
|
- **Android**: Defaults to `10.0.2.2:3000` for emulator development
|
||||||
|
- **iOS**: Uses Capacitor default (`localhost:3000`) for simulator development
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
### Command Line Usage
|
### Command Line Usage
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Default behavior (uses 10.0.2.2 for emulator)
|
# Android - Default behavior (uses 10.0.2.2 for emulator)
|
||||||
./scripts/build-android.sh --dev
|
./scripts/build-android.sh --dev
|
||||||
|
|
||||||
# Custom IP for physical device
|
# Android - Custom IP for physical device
|
||||||
./scripts/build-android.sh --dev --api-ip 192.168.1.100
|
./scripts/build-android.sh --dev --api-ip 192.168.1.100
|
||||||
|
|
||||||
|
# iOS - Default behavior (uses localhost for simulator)
|
||||||
|
./scripts/build-ios.sh --dev
|
||||||
|
|
||||||
|
# iOS - Custom IP for physical device
|
||||||
|
./scripts/build-ios.sh --dev --api-ip 192.168.1.100
|
||||||
|
|
||||||
# Test environment with custom IP
|
# Test environment with custom IP
|
||||||
./scripts/build-android.sh --test --api-ip 192.168.1.100
|
./scripts/build-android.sh --test --api-ip 192.168.1.100
|
||||||
|
./scripts/build-ios.sh --test --api-ip 192.168.1.100
|
||||||
|
|
||||||
# Build and auto-run with custom IP
|
# Build and auto-run with custom IP
|
||||||
./scripts/build-android.sh --dev --api-ip 192.168.1.100 --auto-run
|
./scripts/build-android.sh --dev --api-ip 192.168.1.100 --auto-run
|
||||||
|
./scripts/build-ios.sh --dev --api-ip 192.168.1.100 --auto-run
|
||||||
```
|
```
|
||||||
|
|
||||||
### NPM Scripts
|
### NPM Scripts
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Default development build (uses 10.0.2.2 for emulator)
|
# Android - Default development build (uses 10.0.2.2 for emulator)
|
||||||
npm run build:android:dev
|
npm run build:android:dev
|
||||||
|
|
||||||
# Development build with custom IP (requires IP parameter)
|
# Android - Development build with custom IP (requires IP parameter)
|
||||||
npm run build:android:dev:custom 192.168.1.100
|
npm run build:android:dev:custom 192.168.1.100
|
||||||
|
|
||||||
# Test build with custom IP (requires IP parameter)
|
# iOS - Default development build (uses localhost for simulator)
|
||||||
|
npm run build:ios:dev
|
||||||
|
|
||||||
|
# iOS - Development build with custom IP (requires IP parameter)
|
||||||
|
npm run build:ios:dev:custom 192.168.1.100
|
||||||
|
|
||||||
|
# Test builds with custom IP (requires IP parameter)
|
||||||
npm run build:android:test:custom 192.168.1.100
|
npm run build:android:test:custom 192.168.1.100
|
||||||
|
npm run build:ios:test:custom 192.168.1.100
|
||||||
|
|
||||||
# Development build + auto-run with custom IP
|
# Development build + auto-run with custom IP
|
||||||
npm run build:android:dev:run:custom 192.168.1.100
|
npm run build:android:dev:run:custom 192.168.1.100
|
||||||
|
npm run build:ios:dev:run:custom 192.168.1.100
|
||||||
|
|
||||||
# Test build + auto-run with custom IP
|
# Test build + auto-run with custom IP
|
||||||
npm run build:android:test:run:custom 192.168.1.100
|
npm run build:android:test:run:custom 192.168.1.100
|
||||||
|
npm run build:ios:test:run:custom 192.168.1.100
|
||||||
```
|
```
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
### Scenario 1: Development on Emulator (Default)
|
### Scenario 1: Development on Simulator/Emulator (Default)
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Default behavior - uses 10.0.2.2 for emulator
|
# Android - Default behavior - uses 10.0.2.2 for emulator
|
||||||
npm run build:android:dev
|
npm run build:android:dev
|
||||||
|
|
||||||
# Build and immediately run on emulator
|
# iOS - Default behavior - uses localhost for simulator
|
||||||
|
npm run build:ios:dev
|
||||||
|
|
||||||
|
# Build and immediately run on simulator/emulator
|
||||||
npm run build:android:dev:run
|
npm run build:android:dev:run
|
||||||
|
npm run build:ios:dev:run
|
||||||
```
|
```
|
||||||
|
|
||||||
### Scenario 2: Development on Physical Device
|
### Scenario 2: Development on Physical Device
|
||||||
@@ -72,9 +96,11 @@ npm run build:android:dev:run
|
|||||||
```bash
|
```bash
|
||||||
# Your development server is running on 192.168.1.50:3000
|
# Your development server is running on 192.168.1.50:3000
|
||||||
npm run build:android:dev:custom 192.168.1.50
|
npm run build:android:dev:custom 192.168.1.50
|
||||||
|
npm run build:ios:dev:custom 192.168.1.50
|
||||||
|
|
||||||
# Build and immediately run on device
|
# Build and immediately run on device
|
||||||
npm run build:android:dev:run:custom 192.168.1.50
|
npm run build:android:dev:run:custom 192.168.1.50
|
||||||
|
npm run build:ios:dev:run:custom 192.168.1.50
|
||||||
```
|
```
|
||||||
|
|
||||||
### Scenario 3: Testing on Physical Device
|
### Scenario 3: Testing on Physical Device
|
||||||
@@ -82,20 +108,23 @@ npm run build:android:dev:run:custom 192.168.1.50
|
|||||||
```bash
|
```bash
|
||||||
# Your test server is running on 192.168.1.75:3000
|
# Your test server is running on 192.168.1.75:3000
|
||||||
npm run build:android:test:custom 192.168.1.75
|
npm run build:android:test:custom 192.168.1.75
|
||||||
|
npm run build:ios:test:custom 192.168.1.75
|
||||||
|
|
||||||
# Build and immediately run on device
|
# Build and immediately run on device
|
||||||
npm run build:android:test:run:custom 192.168.1.75
|
npm run build:android:test:run:custom 192.168.1.75
|
||||||
|
npm run build:ios:test:run:custom 192.168.1.75
|
||||||
```
|
```
|
||||||
|
|
||||||
### Scenario 4: Direct Script Usage
|
### Scenario 4: Direct Script Usage
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Default behavior (emulator)
|
# Default behavior (uses platform-appropriate defaults)
|
||||||
./scripts/build-android.sh --dev --studio
|
./scripts/build-android.sh --dev --studio
|
||||||
|
./scripts/build-ios.sh --dev --studio
|
||||||
|
|
||||||
# Custom IP for physical device
|
# Custom IP for physical device
|
||||||
./scripts/build-android.sh --dev --api-ip 192.168.1.100 --studio
|
./scripts/build-android.sh --dev --api-ip 192.168.1.100 --studio
|
||||||
./scripts/build-android.sh --test --api-ip 192.168.1.100 --apk
|
./scripts/build-ios.sh --dev --api-ip 192.168.1.100 --studio
|
||||||
```
|
```
|
||||||
|
|
||||||
## How It Works
|
## How It Works
|
||||||
@@ -104,18 +133,23 @@ npm run build:android:test:run:custom 192.168.1.75
|
|||||||
|
|
||||||
The build system handles API server configuration as follows:
|
The build system handles API server configuration as follows:
|
||||||
|
|
||||||
1. **Default behavior**: Uses `http://10.0.2.2:3000` for emulator development
|
1. **Android default**: Uses Android emulator default (`http://10.0.2.2:3000`)
|
||||||
2. **Custom IP specified**: Overrides with `http://<custom-ip>:3000` for physical device development
|
2. **iOS default**: Uses Capacitor default (`http://localhost:3000`)
|
||||||
3. **Maintains other APIs**: Image and Partner APIs remain at production URLs
|
3. **Custom IP specified**: Overrides with `http://<custom-ip>:3000` for physical device development
|
||||||
4. **Logs the configuration**: Shows which IP is being used in build logs
|
4. **Maintains other APIs**: Image and Partner APIs remain at production URLs
|
||||||
|
5. **Logs the configuration**: Shows which IP is being used in build logs
|
||||||
|
|
||||||
### Build Process
|
### Build Process
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Development mode with default IP (10.0.2.2)
|
# Development mode with Android emulator default (10.0.2.2)
|
||||||
export VITE_DEFAULT_ENDORSER_API_SERVER="http://10.0.2.2:3000"
|
export VITE_DEFAULT_ENDORSER_API_SERVER="http://10.0.2.2:3000"
|
||||||
npm run build:capacitor -- --mode development
|
npm run build:capacitor -- --mode development
|
||||||
|
|
||||||
|
# Development mode with iOS simulator default (localhost)
|
||||||
|
export VITE_DEFAULT_ENDORSER_API_SERVER="http://localhost:3000"
|
||||||
|
npm run build:capacitor -- --mode development
|
||||||
|
|
||||||
# Development mode with custom IP
|
# Development mode with custom IP
|
||||||
export VITE_DEFAULT_ENDORSER_API_SERVER="http://192.168.1.100:3000"
|
export VITE_DEFAULT_ENDORSER_API_SERVER="http://192.168.1.100:3000"
|
||||||
npm run build:capacitor -- --mode development
|
npm run build:capacitor -- --mode development
|
||||||
@@ -123,7 +157,8 @@ npm run build:capacitor -- --mode development
|
|||||||
|
|
||||||
### Default Behavior
|
### Default Behavior
|
||||||
|
|
||||||
- **No `--api-ip` specified**: Uses default emulator IP (`10.0.2.2:3000`)
|
- **Android (no `--api-ip`)**: Uses Android emulator default (`10.0.2.2:3000`)
|
||||||
|
- **iOS (no `--api-ip`)**: Uses Capacitor default (`localhost:3000`)
|
||||||
- **Custom IP specified**: Uses provided IP address for physical device development
|
- **Custom IP specified**: Uses provided IP address for physical device development
|
||||||
- **Invalid IP format**: Build will fail with clear error message
|
- **Invalid IP format**: Build will fail with clear error message
|
||||||
- **Network unreachable**: App will show connection errors at runtime
|
- **Network unreachable**: App will show connection errors at runtime
|
||||||
|
|||||||
@@ -41,6 +41,10 @@
|
|||||||
"build:ios:sync": "./scripts/build-ios.sh --sync",
|
"build:ios:sync": "./scripts/build-ios.sh --sync",
|
||||||
"build:ios:assets": "./scripts/build-ios.sh --assets",
|
"build:ios:assets": "./scripts/build-ios.sh --assets",
|
||||||
"build:ios:deploy": "./scripts/build-ios.sh --deploy",
|
"build:ios:deploy": "./scripts/build-ios.sh --deploy",
|
||||||
|
"build:ios:dev:custom": "./scripts/build-ios.sh --dev --api-ip",
|
||||||
|
"build:ios:test:custom": "./scripts/build-ios.sh --test --api-ip",
|
||||||
|
"build:ios:dev:run:custom": "./scripts/build-ios.sh --dev --api-ip --auto-run",
|
||||||
|
"build:ios:test:run:custom": "./scripts/build-ios.sh --test --api-ip --auto-run",
|
||||||
"build:web": "./scripts/build-web.sh",
|
"build:web": "./scripts/build-web.sh",
|
||||||
"build:web:dev": "./scripts/build-web.sh --dev",
|
"build:web:dev": "./scripts/build-web.sh --dev",
|
||||||
"build:web:test": "./scripts/build-web.sh --test",
|
"build:web:test": "./scripts/build-web.sh --test",
|
||||||
|
|||||||
@@ -193,9 +193,9 @@ if [ "$BUILD_MODE" = "development" ]; then
|
|||||||
export VITE_DEFAULT_ENDORSER_API_SERVER="http://${CUSTOM_API_IP}:3000"
|
export VITE_DEFAULT_ENDORSER_API_SERVER="http://${CUSTOM_API_IP}:3000"
|
||||||
log_info "Android development mode: Using custom IP ${CUSTOM_API_IP} for physical device"
|
log_info "Android development mode: Using custom IP ${CUSTOM_API_IP} for physical device"
|
||||||
else
|
else
|
||||||
# Use default emulator IP (10.0.2.2) for Android development
|
# Use Android emulator IP (10.0.2.2) for Android development
|
||||||
export VITE_DEFAULT_ENDORSER_API_SERVER="http://10.0.2.2:3000"
|
export VITE_DEFAULT_ENDORSER_API_SERVER="http://10.0.2.2:3000"
|
||||||
log_debug "Android development mode: Using default 10.0.2.2 for emulator"
|
log_debug "Android development mode: Using 10.0.2.2 for emulator"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ SYNC_ONLY=false
|
|||||||
ASSETS_ONLY=false
|
ASSETS_ONLY=false
|
||||||
DEPLOY_APP=false
|
DEPLOY_APP=false
|
||||||
AUTO_RUN=false
|
AUTO_RUN=false
|
||||||
|
CUSTOM_API_IP=""
|
||||||
|
|
||||||
# Function to print iOS-specific usage
|
# Function to print iOS-specific usage
|
||||||
print_ios_usage() {
|
print_ios_usage() {
|
||||||
@@ -41,6 +42,7 @@ print_ios_usage() {
|
|||||||
echo " --assets Generate assets only"
|
echo " --assets Generate assets only"
|
||||||
echo " --deploy Deploy app to connected device"
|
echo " --deploy Deploy app to connected device"
|
||||||
echo " --auto-run Auto-run app after build"
|
echo " --auto-run Auto-run app after build"
|
||||||
|
echo " --api-ip <ip> Custom IP address for claim API (uses Capacitor default)"
|
||||||
echo ""
|
echo ""
|
||||||
echo "Common Options:"
|
echo "Common Options:"
|
||||||
echo " -h, --help Show this help message"
|
echo " -h, --help Show this help message"
|
||||||
@@ -54,12 +56,19 @@ print_ios_usage() {
|
|||||||
echo " $0 --clean # Clean only"
|
echo " $0 --clean # Clean only"
|
||||||
echo " $0 --sync # Sync only"
|
echo " $0 --sync # Sync only"
|
||||||
echo " $0 --deploy # Build and deploy to device"
|
echo " $0 --deploy # Build and deploy to device"
|
||||||
|
echo " $0 --dev # Dev build with Capacitor default"
|
||||||
|
echo " $0 --dev --api-ip 192.168.1.100 # Dev build with custom API IP"
|
||||||
echo ""
|
echo ""
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to parse iOS-specific arguments
|
# Function to parse iOS-specific arguments
|
||||||
parse_ios_args() {
|
parse_ios_args() {
|
||||||
for arg in "$@"; do
|
local args=("$@")
|
||||||
|
local i=0
|
||||||
|
|
||||||
|
while [ $i -lt ${#args[@]} ]; do
|
||||||
|
local arg="${args[$i]}"
|
||||||
|
|
||||||
case $arg in
|
case $arg in
|
||||||
--dev|--development)
|
--dev|--development)
|
||||||
BUILD_MODE="development"
|
BUILD_MODE="development"
|
||||||
@@ -100,6 +109,18 @@ parse_ios_args() {
|
|||||||
--auto-run)
|
--auto-run)
|
||||||
AUTO_RUN=true
|
AUTO_RUN=true
|
||||||
;;
|
;;
|
||||||
|
--api-ip)
|
||||||
|
if [ $((i + 1)) -lt ${#args[@]} ]; then
|
||||||
|
CUSTOM_API_IP="${args[$((i + 1))]}"
|
||||||
|
i=$((i + 1)) # Skip the next argument
|
||||||
|
else
|
||||||
|
log_error "Error: --api-ip requires an IP address"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
--api-ip=*)
|
||||||
|
CUSTOM_API_IP="${arg#*=}"
|
||||||
|
;;
|
||||||
-h|--help)
|
-h|--help)
|
||||||
print_ios_usage
|
print_ios_usage
|
||||||
exit 0
|
exit 0
|
||||||
@@ -111,6 +132,7 @@ parse_ios_args() {
|
|||||||
log_warn "Unknown argument: $arg"
|
log_warn "Unknown argument: $arg"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
i=$((i + 1))
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -291,6 +313,13 @@ log_info "Build type: $BUILD_TYPE"
|
|||||||
# Setup environment for Capacitor build
|
# Setup environment for Capacitor build
|
||||||
setup_build_env "capacitor"
|
setup_build_env "capacitor"
|
||||||
|
|
||||||
|
# Override API server for iOS development when custom IP is specified
|
||||||
|
if [ "$BUILD_MODE" = "development" ] && [ -n "$CUSTOM_API_IP" ]; then
|
||||||
|
# Use custom IP for physical device development
|
||||||
|
export VITE_DEFAULT_ENDORSER_API_SERVER="http://${CUSTOM_API_IP}:3000"
|
||||||
|
log_info "iOS development mode: Using custom IP ${CUSTOM_API_IP} for physical device"
|
||||||
|
fi
|
||||||
|
|
||||||
# Setup application directories
|
# Setup application directories
|
||||||
setup_app_directories
|
setup_app_directories
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user