# iOS Test App Setup Guide

**Status:** 📋 **SETUP REQUIRED**  
**Objective:** Create iOS test app for Phase 1 testing

---

## Problem

The iOS test app (`test-apps/ios-test-app/`) does not exist yet. This guide will help you create it.

---

## Quick Setup

### Option 1: Automated Setup (Recommended)

Run the setup script:

```bash
./scripts/setup-ios-test-app.sh
```

This will:
- Create basic directory structure
- Copy HTML from Android test app
- Create `capacitor.config.json` and `package.json`
- Set up basic files

### Option 2: Manual Setup

Follow the steps below to create the iOS test app manually.

---

## Manual Setup Steps

### Step 1: Create Directory Structure

```bash
cd test-apps
mkdir -p ios-test-app/App/App/Public
cd ios-test-app
```

### Step 2: Initialize Capacitor

```bash
# Create package.json
cat > package.json << 'EOF'
{
  "name": "ios-test-app",
  "version": "1.0.0",
  "description": "iOS test app for DailyNotification plugin",
  "scripts": {
    "sync": "npx cap sync ios",
    "open": "npx cap open ios"
  },
  "dependencies": {
    "@capacitor/core": "^5.0.0",
    "@capacitor/ios": "^5.0.0"
  }
}
EOF

# Install dependencies
npm install

# Add iOS platform
npx cap add ios
```

### Step 3: Copy HTML from Android Test App

```bash
# Copy HTML file
cp ../android-test-app/app/src/main/assets/public/index.html App/App/Public/index.html
```

### Step 4: Configure Capacitor

Create `capacitor.config.json`:

```json
{
  "appId": "org.timesafari.dailynotification.test",
  "appName": "DailyNotification Test App",
  "webDir": "App/App/Public",
  "server": {
    "iosScheme": "capacitor"
  },
  "plugins": {
    "DailyNotification": {
      "enabled": true
    }
  }
}
```

### Step 5: Configure Info.plist

Edit `App/App/Info.plist` and add:

```xml
<!-- Background Task Identifiers -->
<key>BGTaskSchedulerPermittedIdentifiers</key>
<array>
    <string>org.timesafari.dailynotification.fetch</string>
    <string>org.timesafari.dailynotification.notify</string>
</array>

<!-- Background Modes -->
<key>UIBackgroundModes</key>
<array>
    <string>background-fetch</string>
    <string>background-processing</string>
    <string>remote-notification</string>
</array>

<!-- Notification Permissions -->
<key>NSUserNotificationsUsageDescription</key>
<string>This app uses notifications to deliver daily updates and reminders.</string>
```

### Step 6: Link Plugin

The plugin needs to be accessible. Options:

**Option A: Local Development (Recommended)**
- Ensure plugin is at `../../ios/Plugin/`
- Capacitor will auto-detect it during sync

**Option B: Via npm**
- Install plugin: `npm install ../../`
- Capacitor will link it automatically

### Step 7: Sync Capacitor

```bash
npx cap sync ios
```

### Step 8: Build and Run

```bash
# Use build script
../../scripts/build-ios-test-app.sh --simulator

# Or open in Xcode
npx cap open ios
# Then press Cmd+R in Xcode
```

---

## Troubleshooting

### Issue: "No Xcode workspace or project found"

**Solution:** Run `npx cap add ios` first to create the Xcode project.

### Issue: Plugin not found

**Solution:** 
1. Ensure plugin exists at `../../ios/Plugin/`
2. Run `npx cap sync ios`
3. Check `App/App/capacitor.plugins.json` contains DailyNotification entry

### Issue: BGTask not running

**Solution:**
1. Verify Info.plist has `BGTaskSchedulerPermittedIdentifiers`
2. Check task registered in AppDelegate
3. Use simulator-only LLDB command to manually trigger (see testing guide)

### Issue: Build failures

**Solution:**
1. Run `pod install` in `App/` directory
2. Clean build folder in Xcode (Cmd+Shift+K)
3. Verify Capacitor plugin path

---

## Verification Checklist

After setup, verify:

- [ ] `test-apps/ios-test-app/` directory exists
- [ ] `App.xcworkspace` or `App.xcodeproj` exists
- [ ] `App/App/Public/index.html` exists
- [ ] `capacitor.config.json` exists
- [ ] `Info.plist` has BGTask identifiers
- [ ] Plugin loads in test app
- [ ] Build script works: `./scripts/build-ios-test-app.sh --simulator`

---

## References

- **Requirements:** `doc/test-app-ios/IOS_TEST_APP_REQUIREMENTS.md`
- **Testing Guide:** `doc/IOS_PHASE1_TESTING_GUIDE.md`
- **Build Script:** `scripts/build-ios-test-app.sh`
- **Setup Script:** `scripts/setup-ios-test-app.sh`

---

**Status:** 📋 **SETUP REQUIRED**  
**Last Updated:** 2025-01-XX

