# Panduan Build iOS App

## Persyaratan
- macOS (iOS development hanya bisa di Mac)
- Xcode 14 atau lebih baru
- CocoaPods
- Apple Developer Account (untuk deploy ke device/App Store)

## Langkah-langkah Build iOS

### 1. Install Dependencies
```bash
npm install
```

### 2. Build Aplikasi React
```bash
npm run build
```

### 3. Tambah iOS Platform (jika belum)
```bash
npx cap add ios
```

### 4. Sync dengan Capacitor
```bash
npx cap sync ios
```

### 5. Buka di Xcode
```bash
npx cap open ios
```

### 6. Build di Xcode

Setelah Xcode terbuka:

1. Pilih target device/simulator di toolbar atas
2. Pilih menu **Product > Build** (⌘B)
3. Untuk run di simulator: **Product > Run** (⌘R)
4. Untuk archive: **Product > Archive**

## Build untuk Testing (Development)

### Run di Simulator
1. Buka Xcode
2. Pilih simulator (iPhone 14, iPad, dll)
3. Klik tombol Play atau tekan ⌘R

### Run di Device Fisik
1. Hubungkan iPhone/iPad via USB
2. Trust device di Mac dan iPhone
3. Di Xcode, pilih device Anda
4. Pilih **Signing & Capabilities** tab
5. Pilih Team (Apple Developer Account)
6. Klik Play untuk install dan run

## Build untuk Production (App Store)

### 1. Setup Signing
1. Buka project di Xcode
2. Pilih target **App**
3. Tab **Signing & Capabilities**
4. Pilih Team (Apple Developer Account)
5. Pastikan Bundle Identifier unik: `com.dms.sales`

### 2. Archive Build
```bash
# Di Xcode:
# Product > Archive
```

Atau via command line:
```bash
cd ios/App
xcodebuild -workspace App.xcworkspace \
  -scheme App \
  -configuration Release \
  -archivePath ./build/App.xcarchive \
  archive
```

### 3. Export IPA
1. Setelah archive selesai, Organizer akan terbuka
2. Pilih archive terbaru
3. Klik **Distribute App**
4. Pilih metode distribusi:
   - **App Store Connect** - untuk upload ke App Store
   - **Ad Hoc** - untuk testing internal
   - **Development** - untuk testing developer
   - **Enterprise** - untuk distribusi internal perusahaan

### 4. Upload ke App Store Connect
1. Pilih **App Store Connect**
2. Klik **Upload**
3. Tunggu proses upload selesai
4. Buka App Store Connect di browser
5. Buat app baru atau pilih app yang ada
6. Submit untuk review

## Testing IPA

### Install via TestFlight
1. Upload IPA ke App Store Connect
2. Tambahkan tester di TestFlight
3. Tester akan menerima email invite
4. Install TestFlight app dari App Store
5. Install app dari TestFlight

### Install via Xcode
```bash
# Connect device
# Drag IPA file ke Xcode Devices window
```

## Update Capacitor Config untuk iOS

Edit `capacitor.config.ts`:
```typescript
import type { CapacitorConfig } from '@capacitor/cli';

const config: CapacitorConfig = {
  appId: 'com.dms.sales',
  appName: 'DMS Sales',
  webDir: 'build',
  ios: {
    contentInset: 'always',
    scrollEnabled: true
  }
};

export default config;
```

## Troubleshooting

### Error: CocoaPods not installed
```bash
sudo gem install cocoapods
```

### Error: Pod install failed
```bash
cd ios/App
pod repo update
pod install
```

### Error: Signing failed
1. Pastikan Apple Developer Account aktif
2. Buat App ID di developer.apple.com
3. Buat Provisioning Profile
4. Download dan install di Xcode

### Error: Build failed - Swift version
1. Buka Xcode
2. Build Settings > Swift Language Version
3. Set ke Swift 5.0 atau lebih baru

### Error: Device not trusted
1. Di iPhone: Settings > General > Device Management
2. Trust developer certificate

## App Icons & Splash Screen

### Generate Icons
1. Buat icon 1024x1024px
2. Gunakan tool online atau:
```bash
npm install -g @capacitor/assets
npx capacitor-assets generate --ios
```

### Custom Splash Screen
1. Edit `ios/App/App/Assets.xcassets/Splash.imageset/`
2. Atau gunakan Capacitor Splash Screen plugin

## Optimasi Build

### Reduce App Size
1. Enable bitcode (jika memungkinkan)
2. Strip debug symbols untuk release
3. Optimize images dan assets

### Performance
1. Enable WKWebView optimizations
2. Use native navigation jika perlu
3. Lazy load components

## Resources

- [Capacitor iOS Documentation](https://capacitorjs.com/docs/ios)
- [Apple Developer Documentation](https://developer.apple.com/documentation/)
- [App Store Review Guidelines](https://developer.apple.com/app-store/review/guidelines/)
- [TestFlight Documentation](https://developer.apple.com/testflight/)
