# iOS Live Activity Setup Guide

This guide walks you through setting up the iOS Live Activity (Dynamic Island & Lock Screen) for shift tracking.

## Prerequisites

- Xcode 14.0 or later
- iOS 16.1+ deployment target
- Physical device for testing (Live Activities don't work in Simulator)

## Setup Steps

### Step 1: Add ShiftActivityAttributes to Widget Extension Target

The `ShiftActivityAttributes.swift` file in `ios/Runner/` needs to be included in **both** the Runner AND ShiftActivityWidget targets:

1. In Xcode, select `Runner/ShiftActivityAttributes.swift` in the Project Navigator
2. Open the **File Inspector** (right panel, first tab)
3. Under **Target Membership**, check both:
   - ✅ `Runner`
   - ✅ `ShiftActivityWidget`

This shares the data model between the main app and the widget extension.

### Step 2: Set Widget Extension Deployment Target

1. In Xcode, select the **ShiftActivityWidget** target (in the left sidebar under TARGETS)
2. Go to the **General** tab
3. Under **Minimum Deployments**, set iOS to `16.1`

### Step 3: Build and Test

1. Select your **physical iOS device** (not Simulator - Live Activities won't work)
2. Build and run the app (⌘+R)
3. Clock in to a shift
4. The Live Activity should appear on:
   - **Lock Screen** (as a banner widget)
   - **Dynamic Island** (on iPhone 14 Pro and later)

## File Structure

```
ios/
├── Runner/
│   ├── AppDelegate.swift              # MethodChannel handlers (calls Flutter)
│   ├── ShiftActivityAttributes.swift  # Shared data model ← ADD TO BOTH TARGETS
│   └── Info.plist                     # Contains NSSupportsLiveActivities
│
└── ShiftActivityWidget/
    ├── ShiftActivityWidgetBundle.swift        # Widget entry point (Xcode generated)
    ├── ShiftActivityWidgetLiveActivity.swift  # Live Activity UI (our custom code)
    ├── ShiftActivityWidget.swift              # Home screen widget (Xcode template)
    ├── ShiftActivityWidgetControl.swift       # Control center (Xcode template)
    └── Info.plist
```

## How It Works

1. **Clock In** → Flutter calls `LiveActivityService.startShiftActivity()`
2. **MethodChannel** → Sends data to native Swift via `com.buyerkiosk.team/live_activity`
3. **AppDelegate** → Creates an `Activity<ShiftActivityAttributes>` using ActivityKit
4. **iOS** → Displays the Live Activity on Lock Screen and Dynamic Island
5. **Updates** → Flutter updates the activity every minute while clocked in
6. **Clock Out** → Flutter calls `endShiftActivity()` to dismiss the activity

## Troubleshooting

### "Cannot find 'ShiftActivityAttributes' in scope"

**Fix:** Add `ShiftActivityAttributes.swift` to the ShiftActivityWidget target membership (Step 1 above).

### Live Activity doesn't appear

1. Make sure device is iOS 16.1+
2. Check Settings → BuyerKiosk Team → Live Activities is enabled
3. Check Xcode console for any errors when clocking in
4. Verify you're testing on a **physical device** (not Simulator)

### Build fails with deployment target error

**Fix:** Set ShiftActivityWidget minimum deployment to iOS 16.1 (Step 2 above).

### "Type 'ShiftActivityAttributes' does not conform to protocol 'ActivityAttributes'"

This means the ActivityKit import is missing. Check `ShiftActivityAttributes.swift` has:
```swift
import ActivityKit
```

## Testing Tips

- Use **Preview** in Xcode to see Live Activity designs without running the full app
- The `#Preview` macro at the bottom of `ShiftActivityWidgetLiveActivity.swift` shows both "working" and "almost done" states
- To force-end a stuck Live Activity, restart your device
