fix(ios): resolve compilation errors and enable successful build

Fixed critical compilation errors preventing iOS plugin build:
- Updated logger API calls from logger.debug(TAG, msg) to logger.log(.debug, msg)
  across all iOS plugin files to match DailyNotificationLogger interface
- Fixed async/await concurrency in makeConditionalRequest using semaphore pattern
- Fixed NotificationContent immutability by creating new instances instead of mutation
- Changed private access control to internal for extension-accessible methods
- Added iOS 15.0+ availability checks for interruptionLevel property
- Fixed static member references using Self.MEMBER_NAME syntax
- Added missing .scheduling case to exhaustive switch statement
- Fixed variable initialization in retry state closures

Added DailyNotificationStorage.swift implementation matching Android pattern.

Updated build scripts with improved error reporting and full log visibility.

iOS plugin now compiles successfully. All build errors resolved.
This commit is contained in:
Matthew Raymer
2025-11-04 22:22:02 -08:00
parent 4be87acc14
commit 8ded555a21
17 changed files with 2000 additions and 196 deletions

291
docs/CONSOLE_BUILD_GUIDE.md Normal file
View File

@@ -0,0 +1,291 @@
# Building Everything from Console
**Author**: Matthew Raymer
**Date**: November 4, 2025
## Quick Start
Build everything (plugin + iOS + Android):
```bash
./scripts/build-all.sh
```
Build specific platform:
```bash
./scripts/build-all.sh ios # iOS only
./scripts/build-all.sh android # Android only
./scripts/build-all.sh all # Everything (default)
```
## What Gets Built
### 1. Plugin Build
- Compiles TypeScript to JavaScript
- Builds native iOS code (Swift)
- Builds native Android code (Kotlin/Java)
- Creates plugin frameworks/bundles
### 2. Android Build
- Builds Android app (`android/app`)
- Creates debug APK
- Output: `android/app/build/outputs/apk/debug/app-debug.apk`
### 3. iOS Build
- Installs CocoaPods dependencies
- Builds iOS app (`ios/App`)
- Creates simulator app bundle
- Output: `ios/App/build/derivedData/Build/Products/Debug-iphonesimulator/App.app`
## Detailed Build Process
### Step-by-Step Build
```bash
# 1. Build plugin (TypeScript + Native)
./scripts/build-native.sh --platform all
# 2. Build Android app
cd android
./gradlew :app:assembleDebug
cd ..
# 3. Build iOS app
cd ios
pod install
cd App
xcodebuild -workspace App.xcworkspace \
-scheme App \
-configuration Debug \
-sdk iphonesimulator \
-destination 'generic/platform=iOS Simulator' \
CODE_SIGN_IDENTITY="" \
CODE_SIGNING_REQUIRED=NO \
CODE_SIGNING_ALLOWED=NO
```
### Platform-Specific Builds
#### Android Only
```bash
# Build plugin for Android
./scripts/build-native.sh --platform android
# Build Android app
cd android
./gradlew :app:assembleDebug
# Install on device/emulator
adb install app/build/outputs/apk/debug/app-debug.apk
```
#### iOS Only
```bash
# Build plugin for iOS
./scripts/build-native.sh --platform ios
# Install CocoaPods dependencies
cd ios
pod install
# Build iOS app
cd App
xcodebuild -workspace App.xcworkspace \
-scheme App \
-configuration Debug \
-sdk iphonesimulator \
CODE_SIGN_IDENTITY="" \
CODE_SIGNING_REQUIRED=NO \
CODE_SIGNING_ALLOWED=NO
# Deploy to simulator (see deployment scripts)
../scripts/build-and-deploy-native-ios.sh
```
## Build Scripts
### Main Build Script
**`scripts/build-all.sh`**
- Builds plugin + iOS + Android
- Handles dependencies automatically
- Provides clear error messages
### Platform-Specific Scripts
**`scripts/build-native.sh`**
- Builds plugin only (TypeScript + native code)
- Supports `--platform ios`, `--platform android`, `--platform all`
**`scripts/build-and-deploy-native-ios.sh`**
- Builds iOS plugin + app
- Deploys to simulator automatically
- Includes booting simulator and launching app
**`test-apps/daily-notification-test/scripts/build-and-deploy-ios.sh`**
- Builds Vue 3 test app
- Syncs web assets
- Deploys to simulator
## Build Outputs
### Android
```
android/app/build/outputs/apk/debug/app-debug.apk
```
### iOS
```
ios/App/build/derivedData/Build/Products/Debug-iphonesimulator/App.app
```
### Plugin
```
ios/build/derivedData/Build/Products/*/DailyNotificationPlugin.framework
android/plugin/build/outputs/aar/plugin-release.aar
```
## Prerequisites
### For All Platforms
- Node.js and npm
- Git
### For Android
- Android SDK
- Java JDK (8 or higher)
- Gradle (or use Gradle wrapper)
### For iOS
- macOS
- Xcode Command Line Tools
- CocoaPods (`gem install cocoapods`)
## Troubleshooting
### Build Fails
```bash
# Clean and rebuild
./scripts/build-native.sh --platform all --clean
# Android: Clean Gradle cache
cd android && ./gradlew clean && cd ..
# iOS: Clean Xcode build
cd ios/App && xcodebuild clean && cd ../..
```
### Dependencies Out of Date
```bash
# Update npm dependencies
npm install
# Update CocoaPods
cd ios && pod update && cd ..
# Update Android dependencies
cd android && ./gradlew --refresh-dependencies && cd ..
```
### iOS Project Not Found
If `ios/App/App.xcworkspace` doesn't exist:
```bash
# Initialize iOS app with Capacitor
cd ios
npx cap sync ios
pod install
```
### Android Build Issues
```bash
# Verify Android SDK
echo $ANDROID_HOME
# Clean build
cd android
./gradlew clean
./gradlew :app:assembleDebug
```
## CI/CD Integration
### GitHub Actions Example
```yaml
name: Build All Platforms
on: [push, pull_request]
jobs:
build:
runs-on: macos-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- name: Build Everything
run: ./scripts/build-all.sh all
```
### Android-Only CI
```yaml
name: Build Android
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- uses: actions/setup-java@v2
- name: Build Android
run: ./scripts/build-all.sh android
```
## Verification
After building, verify outputs:
```bash
# Android APK exists
test -f android/app/build/outputs/apk/debug/app-debug.apk && echo "✓ Android APK"
# iOS app bundle exists
test -d ios/App/build/derivedData/Build/Products/Debug-iphonesimulator/App.app && echo "✓ iOS app"
# Plugin frameworks exist
test -d ios/build/derivedData/Build/Products/*/DailyNotificationPlugin.framework && echo "✓ iOS plugin"
test -f android/plugin/build/outputs/aar/plugin-release.aar && echo "✓ Android plugin"
```
## Next Steps
After building:
1. **Deploy Android**: `adb install android/app/build/outputs/apk/debug/app-debug.apk`
2. **Deploy iOS**: Use `scripts/build-and-deploy-native-ios.sh`
3. **Test**: Run plugin tests and verify functionality
4. **Debug**: Use platform-specific debugging tools
## References
- [Build Native Script](scripts/build-native.sh)
- [iOS Deployment Guide](docs/standalone-ios-simulator-guide.md)
- [Android Build Guide](BUILDING.md)

View File

@@ -0,0 +1,199 @@
# Viewing Build Errors - Full Output Guide
**Author**: Matthew Raymer
**Date**: November 4, 2025
## Quick Methods to See Full Errors
### Method 1: Run Build Script and Check Log Files
```bash
# Run the build script
./scripts/build-native.sh --platform ios
# If it fails, check the log files:
cat /tmp/xcodebuild_device.log # Device build errors
cat /tmp/xcodebuild_simulator.log # Simulator build errors
# View only errors:
grep -E "(error:|warning:)" /tmp/xcodebuild_simulator.log
```
### Method 2: Run xcodebuild Directly (No Script Filtering)
```bash
# Build for simulator with full output
cd ios
xcodebuild -workspace DailyNotificationPlugin.xcworkspace \
-scheme DailyNotificationPlugin \
-configuration Debug \
-sdk iphonesimulator \
-destination 'generic/platform=iOS Simulator' \
CODE_SIGN_IDENTITY="" \
CODE_SIGNING_REQUIRED=NO \
CODE_SIGNING_ALLOWED=NO \
| tee build-output.log
# Then view errors:
grep -E "(error:|warning:)" build-output.log
```
### Method 3: Redirect to File and View
```bash
# Save full output to file
./scripts/build-native.sh --platform ios 2>&1 | tee build-full.log
# View errors
grep -E "(error:|warning:|ERROR|FAILED)" build-full.log
# View last 100 lines
tail -100 build-full.log
```
### Method 4: Use xcodebuild with Verbose Output
```bash
cd ios
# Build with verbose output
xcodebuild -workspace DailyNotificationPlugin.xcworkspace \
-scheme DailyNotificationPlugin \
-configuration Debug \
-sdk iphonesimulator \
-destination 'generic/platform=iOS Simulator' \
CODE_SIGN_IDENTITY="" \
CODE_SIGNING_REQUIRED=NO \
CODE_SIGNING_ALLOWED=NO \
-verbose \
2>&1 | tee build-verbose.log
# Extract just errors
grep -E "^error:" build-verbose.log | head -50
```
## Filtering Output
### Show Only Errors
```bash
# From log file
grep -E "^error:" /tmp/xcodebuild_simulator.log
# From live output
./scripts/build-native.sh --platform ios 2>&1 | grep -E "(error:|ERROR)"
```
### Show Errors with Context (5 lines before/after)
```bash
grep -E "(error:|warning:)" -A 5 -B 5 /tmp/xcodebuild_simulator.log | head -100
```
### Count Errors
```bash
grep -c "error:" /tmp/xcodebuild_simulator.log
```
### Show Errors Grouped by File
```bash
grep "error:" /tmp/xcodebuild_simulator.log | cut -d: -f1-3 | sort | uniq -c | sort -rn
```
## Common Error Patterns
### Swift Compilation Errors
```bash
# Find all Swift compilation errors
grep -E "\.swift.*error:" /tmp/xcodebuild_simulator.log
# Find missing type errors
grep -E "cannot find type.*in scope" /tmp/xcodebuild_simulator.log
# Find import errors
grep -E "No such module|Cannot find.*in scope" /tmp/xcodebuild_simulator.log
```
### CocoaPods Errors
```bash
# Find CocoaPods errors
grep -E "(pod|CocoaPods)" /tmp/xcodebuild_simulator.log -i
```
### Build System Errors
```bash
# Find build system errors
grep -E "(BUILD FAILED|error:)" /tmp/xcodebuild_simulator.log
```
## Debugging Tips
### See Full Command Being Run
Add `set -x` at the top of the script, or run:
```bash
bash -x ./scripts/build-native.sh --platform ios 2>&1 | tee build-debug.log
```
### Check Exit Codes
```bash
./scripts/build-native.sh --platform ios
echo "Exit code: $?"
```
### View Build Settings
```bash
cd ios
xcodebuild -workspace DailyNotificationPlugin.xcworkspace \
-scheme DailyNotificationPlugin \
-showBuildSettings 2>&1 | grep -E "(SWIFT|FRAMEWORK|HEADER)"
```
## Example: Full Debug Session
```bash
# 1. Run build and save everything
./scripts/build-native.sh --platform ios 2>&1 | tee build-full.log
# 2. Check exit code
echo "Build exit code: $?"
# 3. Extract errors
echo "=== ERRORS ===" > errors.txt
grep -E "(error:|ERROR)" build-full.log >> errors.txt
# 4. Extract warnings
echo "=== WARNINGS ===" >> errors.txt
grep -E "(warning:|WARNING)" build-full.log >> errors.txt
# 5. View errors file
cat errors.txt
# 6. Check log files created by script
ls -lh /tmp/xcodebuild*.log
```
## Quick Reference
```bash
# Most common: View simulator build errors
cat /tmp/xcodebuild_simulator.log | grep -E "(error:|warning:)" | head -30
# View full build log
cat /tmp/xcodebuild_simulator.log | less
# Search for specific error
grep -i "cannot find type" /tmp/xcodebuild_simulator.log
# Count errors by type
grep "error:" /tmp/xcodebuild_simulator.log | cut -d: -f4 | sort | uniq -c | sort -rn
```

View File

@@ -0,0 +1,185 @@
# iOS Native Interface Structure
**Author**: Matthew Raymer
**Date**: November 4, 2025
## Overview
The iOS native interface mirrors the Android structure, providing the same functionality through iOS-specific implementations.
## Directory Structure
```
ios/App/App/
├── AppDelegate.swift # Application lifecycle (equivalent to PluginApplication.java)
├── ViewController.swift # Main view controller (equivalent to MainActivity.java)
├── SceneDelegate.swift # Scene-based lifecycle (iOS 13+)
├── Info.plist # App configuration (equivalent to AndroidManifest.xml)
├── capacitor.config.json # Capacitor configuration
├── config.xml # Cordova compatibility
└── public/ # Web assets (equivalent to assets/public/)
├── index.html
├── capacitor.js
└── capacitor_plugins.js
```
## File Descriptions
### AppDelegate.swift
**Purpose**: Application lifecycle management
**Equivalent**: `PluginApplication.java` on Android
- Handles app lifecycle events (launch, background, foreground, termination)
- Registers for push notifications
- Handles URL schemes and universal links
- Initializes plugin demo fetcher (equivalent to Android's `PluginApplication.onCreate()`)
**Key Methods**:
- `application(_:didFinishLaunchingWithOptions:)` - App initialization
- `applicationDidEnterBackground(_:)` - Background handling
- `applicationWillEnterForeground(_:)` - Foreground handling
- `application(_:didRegisterForRemoteNotificationsWithDeviceToken:)` - Push notification registration
### ViewController.swift
**Purpose**: Main view controller extending Capacitor's bridge
**Equivalent**: `MainActivity.java` on Android
- Extends `CAPBridgeViewController` (Capacitor's bridge view controller)
- Initializes plugin and registers native fetcher
- Handles view lifecycle events
**Key Methods**:
- `viewDidLoad()` - View initialization
- `initializePlugin()` - Plugin registration (equivalent to Android's plugin registration)
### SceneDelegate.swift
**Purpose**: Scene-based lifecycle management (iOS 13+)
**Equivalent**: None on Android (iOS-specific)
- Handles scene creation and lifecycle
- Manages window and view controller setup
- Required for modern iOS apps using scene-based architecture
### Info.plist
**Purpose**: App configuration and permissions
**Equivalent**: `AndroidManifest.xml` on Android
**Key Entries**:
- `CFBundleIdentifier` - App bundle ID
- `NSUserNotificationsUsageDescription` - Notification permission description
- `UIBackgroundModes` - Background modes (fetch, processing, remote-notification)
- `BGTaskSchedulerPermittedIdentifiers` - Background task identifiers
- `UIApplicationSceneManifest` - Scene configuration
## Comparison: Android vs iOS
| Component | Android | iOS |
|-----------|---------|-----|
| **Application Class** | `PluginApplication.java` | `AppDelegate.swift` |
| **Main Activity** | `MainActivity.java` | `ViewController.swift` |
| **Config File** | `AndroidManifest.xml` | `Info.plist` |
| **Web Assets** | `assets/public/` | `public/` |
| **Lifecycle** | `onCreate()`, `onResume()`, etc. | `viewDidLoad()`, `viewWillAppear()`, etc. |
| **Bridge** | `BridgeActivity` | `CAPBridgeViewController` |
## Plugin Registration
### Android
```java
public class PluginApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
NativeNotificationContentFetcher demoFetcher = new DemoNativeFetcher();
DailyNotificationPlugin.setNativeFetcher(demoFetcher);
}
}
```
### iOS
```swift
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Plugin registration happens in ViewController after Capacitor bridge is initialized
return true
}
}
class ViewController: CAPBridgeViewController {
override func viewDidLoad() {
super.viewDidLoad()
initializePlugin()
}
private func initializePlugin() {
// Register demo native fetcher if implementing SPI
// DailyNotificationPlugin.setNativeFetcher(DemoNativeFetcher())
}
}
```
## Build Process
1. **Swift Compilation**: Compiles `AppDelegate.swift`, `ViewController.swift`, `SceneDelegate.swift`
2. **Capacitor Integration**: Links with Capacitor framework and plugin
3. **Web Assets**: Copies `public/` directory to app bundle
4. **Info.plist**: Processes app configuration and permissions
5. **App Bundle**: Creates `.app` bundle for installation
## Permissions
### Android (AndroidManifest.xml)
```xml
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
```
### iOS (Info.plist)
```xml
<key>NSUserNotificationsUsageDescription</key>
<string>This app uses notifications to deliver daily updates and reminders.</string>
<key>UIBackgroundModes</key>
<array>
<string>background-fetch</string>
<string>background-processing</string>
<string>remote-notification</string>
</array>
```
## Background Tasks
### Android
- Uses `WorkManager` and `AlarmManager`
- Declared in `AndroidManifest.xml` receivers
### iOS
- Uses `BGTaskScheduler` and `UNUserNotificationCenter`
- Declared in `Info.plist` with `BGTaskSchedulerPermittedIdentifiers`
## Next Steps
1. Ensure Xcode project includes these Swift files
2. Configure build settings in Xcode project
3. Add app icons and launch screen
4. Test plugin registration and native fetcher
5. Verify background tasks work correctly
## References
- [Capacitor iOS Documentation](https://capacitorjs.com/docs/ios)
- [iOS App Lifecycle](https://developer.apple.com/documentation/uikit/app_and_environment/managing_your_app_s_life_cycle)
- [Background Tasks](https://developer.apple.com/documentation/backgroundtasks)