forked from trent_larson/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
|
||||
**Date**: 2025-01-27
|
||||
@@ -10,61 +10,85 @@ When deploying TimeSafari to physical Android devices during development, you ma
|
||||
|
||||
## Problem
|
||||
|
||||
During Android development:
|
||||
- **Emulator**: Uses `10.0.2.2:3000` to access host machine's localhost (default)
|
||||
- **Physical Device**: Cannot access `localhost` or `10.0.2.2` - needs actual IP address
|
||||
During mobile development:
|
||||
- **Android Emulator**: Uses `10.0.2.2:3000` to access host machine's localhost (Android emulator default)
|
||||
- **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
|
||||
|
||||
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
|
||||
|
||||
### Command Line Usage
|
||||
|
||||
```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
|
||||
|
||||
# Custom IP for physical device
|
||||
# Android - Custom IP for physical device
|
||||
./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
|
||||
./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
|
||||
./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
|
||||
|
||||
```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
|
||||
|
||||
# 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
|
||||
|
||||
# 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:ios:test:custom 192.168.1.100
|
||||
|
||||
# Development build + auto-run with custom IP
|
||||
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
|
||||
npm run build:android:test:run:custom 192.168.1.100
|
||||
npm run build:ios:test:run:custom 192.168.1.100
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
### Scenario 1: Development on Emulator (Default)
|
||||
### Scenario 1: Development on Simulator/Emulator (Default)
|
||||
|
||||
```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
|
||||
|
||||
# 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:ios:dev:run
|
||||
```
|
||||
|
||||
### Scenario 2: Development on Physical Device
|
||||
@@ -72,9 +96,11 @@ npm run build:android:dev:run
|
||||
```bash
|
||||
# Your development server is running on 192.168.1.50:3000
|
||||
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
|
||||
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
|
||||
@@ -82,20 +108,23 @@ npm run build:android:dev:run:custom 192.168.1.50
|
||||
```bash
|
||||
# Your test server is running on 192.168.1.75:3000
|
||||
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
|
||||
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
|
||||
|
||||
```bash
|
||||
# Default behavior (emulator)
|
||||
# Default behavior (uses platform-appropriate defaults)
|
||||
./scripts/build-android.sh --dev --studio
|
||||
./scripts/build-ios.sh --dev --studio
|
||||
|
||||
# Custom IP for physical device
|
||||
./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
|
||||
@@ -104,18 +133,23 @@ npm run build:android:test:run:custom 192.168.1.75
|
||||
|
||||
The build system handles API server configuration as follows:
|
||||
|
||||
1. **Default behavior**: Uses `http://10.0.2.2:3000` for emulator development
|
||||
2. **Custom IP specified**: Overrides with `http://<custom-ip>:3000` for physical device development
|
||||
3. **Maintains other APIs**: Image and Partner APIs remain at production URLs
|
||||
4. **Logs the configuration**: Shows which IP is being used in build logs
|
||||
1. **Android default**: Uses Android emulator default (`http://10.0.2.2:3000`)
|
||||
2. **iOS default**: Uses Capacitor default (`http://localhost:3000`)
|
||||
3. **Custom IP specified**: Overrides with `http://<custom-ip>:3000` for physical device development
|
||||
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
|
||||
|
||||
```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"
|
||||
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
|
||||
export VITE_DEFAULT_ENDORSER_API_SERVER="http://192.168.1.100:3000"
|
||||
npm run build:capacitor -- --mode development
|
||||
@@ -123,7 +157,8 @@ npm run build:capacitor -- --mode development
|
||||
|
||||
### 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
|
||||
- **Invalid IP format**: Build will fail with clear error message
|
||||
- **Network unreachable**: App will show connection errors at runtime
|
||||
|
||||
Reference in New Issue
Block a user