Compare commits

...

2 Commits

Author SHA1 Message Date
Matthew Raymer 8ded555a21 fix(ios): resolve compilation errors and enable successful build 1 day ago
Matthew Raymer 4be87acc14 feat(ios): add iOS deployment support and web assets parity 2 days ago
  1. 291
      docs/CONSOLE_BUILD_GUIDE.md
  2. 199
      docs/VIEWING_BUILD_ERRORS.md
  3. 64
      docs/WEB_ASSETS_PARITY.md
  4. 185
      docs/ios-native-interface.md
  5. 548
      docs/standalone-ios-simulator-guide.md
  6. 106
      ios/App/App/AppDelegate.swift
  7. 119
      ios/App/App/Info.plist
  8. 61
      ios/App/App/SceneDelegate.swift
  9. 69
      ios/App/App/ViewController.swift
  10. 638
      ios/App/App/public/index.html
  11. 4
      ios/DailyNotificationPlugin.podspec
  12. 28
      ios/Plugin/DailyNotificationBackgroundTaskManager.swift
  13. 6
      ios/Plugin/DailyNotificationBackgroundTasks.swift
  14. 5
      ios/Plugin/DailyNotificationCallbacks.swift
  15. 79
      ios/Plugin/DailyNotificationETagManager.swift
  16. 47
      ios/Plugin/DailyNotificationErrorHandler.swift
  17. 200
      ios/Plugin/DailyNotificationPerformanceOptimizer.swift
  18. 38
      ios/Plugin/DailyNotificationPlugin.swift
  19. 412
      ios/Plugin/DailyNotificationStorage.swift
  20. 14
      ios/Podfile.lock
  21. 16
      nvm-install.sh
  22. 12
      package-lock.json
  23. 245
      scripts/build-all.sh
  24. 161
      scripts/build-and-deploy-native-ios.sh
  25. 467
      scripts/build-native.sh
  26. 250
      scripts/setup-ruby.sh
  27. 183
      test-apps/daily-notification-test/docs/IOS_BUILD_QUICK_REFERENCE.md
  28. 150
      test-apps/daily-notification-test/scripts/build-and-deploy-ios.sh

291
docs/CONSOLE_BUILD_GUIDE.md

@ -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)

199
docs/VIEWING_BUILD_ERRORS.md

@ -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
```

64
docs/WEB_ASSETS_PARITY.md

@ -0,0 +1,64 @@
# Web Assets Structure - Android and iOS Parity
**Author**: Matthew Raymer
**Date**: November 4, 2025
## Source of Truth
The **`www/`** directory is the source of truth for web assets. Both Android and iOS app directories should match this structure.
## Directory Structure
```
www/ # Source of truth (edit here)
├── index.html # Main test interface
android/app/src/main/assets/ # Android (synced from www/)
├── capacitor.plugins.json # Auto-generated by Capacitor
└── public/ # Web assets (must match www/)
└── index.html # Synced from www/index.html
ios/App/App/ # iOS (synced from www/)
├── capacitor.config.json # Capacitor configuration
└── public/ # Web assets (must match www/)
└── index.html # Synced from www/index.html
```
## Synchronization
Both `android/app/src/main/assets/public/` and `ios/App/App/public/` should match `www/` after running:
```bash
# Sync web assets to both platforms
npx cap sync
# Or sync individually
npx cap sync android
npx cap sync ios
```
## Key Points
1. **Edit source files in `www/`** - Never edit platform-specific copies directly
2. **Both platforms should match** - After sync, `android/.../assets/public/` and `ios/App/App/public/` should be identical
3. **Capacitor handles sync** - `npx cap sync` copies files from `www/` to platform directories
4. **Auto-generated files** - `capacitor.plugins.json`, `capacitor.js`, etc. are generated by Capacitor
## Verification
After syncing, verify both platforms match:
```bash
# Check file sizes match
ls -lh www/index.html android/app/src/main/assets/public/index.html ios/App/App/public/index.html
# Compare contents
diff www/index.html android/app/src/main/assets/public/index.html
diff www/index.html ios/App/App/public/index.html
```
## Notes
- **Cordova files**: iOS may have empty `cordova.js` and `cordova_plugins.js` files. These are harmless but should be removed if not using Cordova compatibility.
- **Capacitor runtime**: Capacitor generates `capacitor.js` and `capacitor_plugins.js` during sync - these are auto-generated and should not be manually edited.

185
docs/ios-native-interface.md

@ -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)

548
docs/standalone-ios-simulator-guide.md

@ -0,0 +1,548 @@
# Running iOS Apps in Standalone Simulator (Without Xcode UI)
**Author**: Matthew Raymer
**Last Updated**: 2025-11-04
**Version**: 1.0.0
## Overview
This guide demonstrates how to run DailyNotification plugin test apps in a standalone iOS Simulator without using Xcode UI. This method is useful for development, CI/CD pipelines, and command-line workflows.
**There are two different test apps:**
1. **Native iOS Development App** (`ios/App`) - Simple Capacitor app for plugin development
2. **Vue 3 Test App** (`test-apps/daily-notification-test`) - Full-featured Vue 3 Capacitor app for comprehensive testing
## Prerequisites
### Required Software
- **Xcode** with command line tools (`xcode-select --install`)
- **iOS Simulator** (included with Xcode)
- **CocoaPods** (`gem install cocoapods`)
- **Node.js** and **npm** (for TypeScript compilation)
- **Capacitor CLI** (`npm install -g @capacitor/cli`) - for Vue 3 test app
### System Requirements
- **macOS** (required for iOS development)
- **RAM**: 4GB minimum, 8GB recommended
- **Storage**: 5GB free space for simulator and dependencies
---
## Scenario 1: Native iOS Development App (`ios/App`)
The `ios/App` directory contains a simple Capacitor-based development app, similar to `android/app`. This is used for quick plugin testing and development.
### Step-by-Step Process
#### 1. Check Available Simulators
```bash
# List available iOS simulators
xcrun simctl list devices available
# Example output:
# iPhone 15 Pro (iOS 17.0)
# iPhone 14 (iOS 16.4)
# iPad Pro (12.9-inch) (iOS 17.0)
```
#### 2. Boot a Simulator
```bash
# Boot a specific simulator device
xcrun simctl boot "iPhone 15 Pro"
# Or boot by device ID
xcrun simctl boot <DEVICE_ID>
# Verify simulator is running
xcrun simctl list devices | grep Booted
```
**Alternative: Open Simulator UI**
```bash
# Open Simulator app (allows visual interaction)
open -a Simulator
```
#### 3. Build the Plugin
```bash
# Navigate to project directory
cd /path/to/daily-notification-plugin
# Build plugin for iOS
./scripts/build-native.sh --platform ios
```
**What this does:**
- Compiles TypeScript to JavaScript
- Builds iOS native code (Swift)
- Creates plugin framework
- Builds for simulator
#### 4. Build Native iOS Development App
```bash
# Navigate to iOS directory
cd ios
# Install CocoaPods dependencies
pod install
# Build the development app for simulator
cd App
xcodebuild -workspace App.xcworkspace \
-scheme App \
-configuration Debug \
-sdk iphonesimulator \
-destination 'platform=iOS Simulator,name=iPhone 15 Pro' \
-derivedDataPath build/derivedData \
CODE_SIGN_IDENTITY="" \
CODE_SIGNING_REQUIRED=NO \
CODE_SIGNING_ALLOWED=NO \
clean build
```
#### 5. Install App on Simulator
```bash
# Find the built app
APP_PATH=$(find build/derivedData -name "*.app" -type d -path "*/Build/Products/*-iphonesimulator/*.app" | head -1)
# Install app on simulator
xcrun simctl install booted "$APP_PATH"
```
#### 6. Launch the App
```bash
# Get bundle identifier from Info.plist
BUNDLE_ID=$(plutil -extract CFBundleIdentifier raw App/Info.plist)
# Launch the app
xcrun simctl launch booted "$BUNDLE_ID"
# Example:
# xcrun simctl launch booted com.timesafari.dailynotification
```
#### 7. Monitor App Logs
```bash
# View all logs
xcrun simctl spawn booted log stream
# Filter for specific processes
xcrun simctl spawn booted log stream --predicate 'processImagePath contains "App"'
# View system logs
log stream --predicate 'processImagePath contains "App"' --level debug
```
### Complete Command Sequence for Native iOS App
```bash
# 1. Boot simulator
xcrun simctl boot "iPhone 15 Pro" || open -a Simulator
# 2. Build plugin
cd /path/to/daily-notification-plugin
./scripts/build-native.sh --platform ios
# 3. Build native iOS app
cd ios
pod install
cd App
xcodebuild -workspace App.xcworkspace \
-scheme App \
-configuration Debug \
-sdk iphonesimulator \
-destination 'platform=iOS Simulator,name=iPhone 15 Pro' \
CODE_SIGN_IDENTITY="" \
CODE_SIGNING_REQUIRED=NO \
CODE_SIGNING_ALLOWED=NO
# 4. Install app
APP_PATH=$(find build/derivedData -name "*.app" -type d | head -1)
xcrun simctl install booted "$APP_PATH"
# 5. Launch app
BUNDLE_ID=$(plutil -extract CFBundleIdentifier raw App/Info.plist)
xcrun simctl launch booted "$BUNDLE_ID"
```
---
## Scenario 2: Vue 3 Test App (`test-apps/daily-notification-test`)
The `test-apps/daily-notification-test` directory contains a full-featured Vue 3 Capacitor app with comprehensive testing interface, similar to the Android test app.
### Step-by-Step Process
#### 1. Check Available Simulators
```bash
# List available iOS simulators
xcrun simctl list devices available
```
#### 2. Boot a Simulator
```bash
# Boot a specific simulator device
xcrun simctl boot "iPhone 15 Pro"
# Or open Simulator UI
open -a Simulator
```
#### 3. Build the Plugin
```bash
# Navigate to project directory
cd /path/to/daily-notification-plugin
# Build plugin for iOS
./scripts/build-native.sh --platform ios
```
#### 4. Set Up Vue 3 Test App iOS Project
```bash
# Navigate to test app
cd test-apps/daily-notification-test
# Install dependencies
npm install
# Add iOS platform (if not already added)
npx cap add ios
# Sync web assets with iOS project
npx cap sync ios
```
#### 5. Build Vue 3 Test App
```bash
# Build web assets (Vue 3 app)
npm run build
# Sync with iOS project
npx cap sync ios
# Build iOS app for simulator
cd ios/App
xcodebuild -workspace App.xcworkspace \
-scheme App \
-configuration Debug \
-sdk iphonesimulator \
-destination 'platform=iOS Simulator,name=iPhone 15 Pro' \
-derivedDataPath build/derivedData \
CODE_SIGN_IDENTITY="" \
CODE_SIGNING_REQUIRED=NO \
CODE_SIGNING_ALLOWED=NO
```
#### 6. Install App on Simulator
```bash
# Find the built app
APP_PATH=$(find build/derivedData -name "*.app" -type d -path "*/Build/Products/*-iphonesimulator/*.app" | head -1)
# Install app on simulator
xcrun simctl install booted "$APP_PATH"
```
#### 7. Launch the App
```bash
# Get bundle identifier
BUNDLE_ID=$(plutil -extract CFBundleIdentifier raw App/Info.plist)
# Launch the app
xcrun simctl launch booted "$BUNDLE_ID"
# Example:
# xcrun simctl launch booted com.timesafari.dailynotification.test
```
### Complete Command Sequence for Vue 3 Test App
```bash
# 1. Boot simulator
xcrun simctl boot "iPhone 15 Pro" || open -a Simulator
# 2. Build plugin
cd /path/to/daily-notification-plugin
./scripts/build-native.sh --platform ios
# 3. Set up Vue 3 test app
cd test-apps/daily-notification-test
npm install
npm run build
# 4. Sync with iOS
npx cap sync ios
# 5. Build iOS app
cd ios/App
xcodebuild -workspace App.xcworkspace \
-scheme App \
-configuration Debug \
-sdk iphonesimulator \
-destination 'platform=iOS Simulator,name=iPhone 15 Pro' \
CODE_SIGN_IDENTITY="" \
CODE_SIGNING_REQUIRED=NO \
CODE_SIGNING_ALLOWED=NO
# 6. Install app
APP_PATH=$(find build/derivedData -name "*.app" -type d | head -1)
xcrun simctl install booted "$APP_PATH"
# 7. Launch app
BUNDLE_ID=$(plutil -extract CFBundleIdentifier raw App/Info.plist)
xcrun simctl launch booted "$BUNDLE_ID"
```
---
## Alternative Methods
### Method 1: Using Capacitor CLI (Vue 3 Test App Only)
```bash
cd test-apps/daily-notification-test
# Build and run in one command
npx cap run ios
# This will:
# - Build the plugin
# - Sync web assets
# - Build and install app
# - Launch in simulator
```
**Note**: This method only works for the Vue 3 test app, not the native iOS development app.
### Method 2: Using Automated Scripts
#### For Native iOS App (`ios/App`)
Create `scripts/build-and-deploy-native-ios.sh`:
```bash
#!/bin/bash
set -e
echo "🔨 Building plugin..."
cd /path/to/daily-notification-plugin
./scripts/build-native.sh --platform ios
echo "📱 Booting simulator..."
xcrun simctl boot "iPhone 15 Pro" 2>/dev/null || open -a Simulator
echo "🏗️ Building native iOS app..."
cd ios
pod install
cd App
xcodebuild -workspace App.xcworkspace \
-scheme App \
-configuration Debug \
-sdk iphonesimulator \
-destination 'platform=iOS Simulator,name=iPhone 15 Pro' \
CODE_SIGN_IDENTITY="" \
CODE_SIGNING_REQUIRED=NO \
CODE_SIGNING_ALLOWED=NO
APP_PATH=$(find build/derivedData -name "*.app" -type d | head -1)
xcrun simctl install booted "$APP_PATH"
BUNDLE_ID=$(plutil -extract CFBundleIdentifier raw App/Info.plist)
xcrun simctl launch booted "$BUNDLE_ID"
```
#### For Vue 3 Test App
Use the existing script:
```bash
cd test-apps/daily-notification-test
./scripts/build-and-deploy-ios.sh
```
### Method 3: Manual Xcode Build
```bash
# Open project in Xcode
open ios/App/App.xcworkspace # For native app
# OR
open test-apps/daily-notification-test/ios/App/App.xcworkspace # For Vue 3 app
# Then:
# 1. Select simulator target
# 2. Click Run button (⌘R)
# 3. App builds and launches automatically
```
---
## Simulator Management
### List Available Devices
```bash
# List all devices
xcrun simctl list devices
# List only available devices
xcrun simctl list devices available
# List booted devices
xcrun simctl list devices | grep Booted
```
### Shutdown Simulator
```bash
# Shutdown specific device
xcrun simctl shutdown "iPhone 15 Pro"
# Shutdown all devices
xcrun simctl shutdown all
```
### Reset Simulator
```bash
# Erase all content and settings
xcrun simctl erase "iPhone 15 Pro"
# Reset and boot
xcrun simctl erase "iPhone 15 Pro" && xcrun simctl boot "iPhone 15 Pro"
```
### Delete App from Simulator
```bash
# Uninstall app (replace with correct bundle ID)
xcrun simctl uninstall booted com.timesafari.dailynotification
# OR for Vue 3 test app:
xcrun simctl uninstall booted com.timesafari.dailynotification.test
# Or reset entire simulator
xcrun simctl erase booted
```
---
## Comparison: Native iOS App vs Vue 3 Test App
| Feature | Native iOS App (`ios/App`) | Vue 3 Test App (`test-apps/...`) |
|---------|---------------------------|----------------------------------|
| **Purpose** | Quick plugin development testing | Comprehensive testing with UI |
| **Frontend** | Simple HTML/Capacitor | Vue 3 with full UI |
| **Build Steps** | Plugin + iOS build | Plugin + Vue build + iOS build |
| **Capacitor Sync** | Not required | Required (`npx cap sync ios`) |
| **Best For** | Quick native testing | Full integration testing |
| **Bundle ID** | `com.timesafari.dailynotification` | `com.timesafari.dailynotification.test` |
---
## Comparison with Android
| Task | Android Native App | iOS Native App | Vue 3 Test App (iOS) |
|------|-------------------|----------------|---------------------|
| List devices | `emulator -list-avds` | `xcrun simctl list devices` | `xcrun simctl list devices` |
| Boot device | `emulator -avd <name>` | `xcrun simctl boot <name>` | `xcrun simctl boot <name>` |
| Install app | `adb install <apk>` | `xcrun simctl install booted <app>` | `xcrun simctl install booted <app>` |
| Launch app | `adb shell am start` | `xcrun simctl launch booted <bundle>` | `xcrun simctl launch booted <bundle>` |
| View logs | `adb logcat` | `xcrun simctl spawn booted log stream` | `xcrun simctl spawn booted log stream` |
| Build command | `./gradlew assembleDebug` | `xcodebuild -workspace ...` | `xcodebuild -workspace ...` |
---
## Troubleshooting
### Simulator Won't Boot
```bash
# Check Xcode command line tools
xcode-select -p
# Reinstall command line tools
sudo xcode-select --reset
# Verify simulator runtime
xcrun simctl runtime list
```
### Build Fails
```bash
# Clean build folder
cd ios/App # or ios/App for Vue 3 app
xcodebuild clean -workspace App.xcworkspace -scheme App
# Reinstall CocoaPods dependencies
cd ../.. # Back to ios/ directory
pod install --repo-update
# Rebuild
cd App
xcodebuild -workspace App.xcworkspace -scheme App -configuration Debug
```
### App Won't Install
```bash
# Check if simulator is booted
xcrun simctl list devices | grep Booted
# Verify app path exists
ls -la ios/App/build/derivedData/Build/Products/Debug-iphonesimulator/
# Check bundle identifier
plutil -extract CFBundleIdentifier raw ios/App/App/Info.plist
```
### Vue 3 App: Web Assets Not Syncing
```bash
# Rebuild web assets
cd test-apps/daily-notification-test
npm run build
# Force sync
npx cap sync ios --force
# Verify assets are synced
ls -la ios/App/App/public/
```
### Logs Not Showing
```bash
# Use Console.app for better log viewing
open -a Console
# Or use log command with filters
log stream --predicate 'processImagePath contains "App"' --level debug --style compact
```
---
## Additional Resources
- [Capacitor iOS Documentation](https://capacitorjs.com/docs/ios)
- [Xcode Command Line Tools](https://developer.apple.com/xcode/resources/)
- [Simulator Documentation](https://developer.apple.com/documentation/xcode/running-your-app-in-the-simulator-or-on-a-device)
---
**Note**: iOS development requires macOS. This guide assumes you're running on a Mac with Xcode installed.
**Key Distinction**:
- **`ios/App`** = Native iOS development app (simple, for quick testing)
- **`test-apps/daily-notification-test`** = Vue 3 test app (full-featured, for comprehensive testing)

106
ios/App/App/AppDelegate.swift

@ -0,0 +1,106 @@
//
// AppDelegate.swift
// DailyNotification Test App
//
// Application delegate for the Daily Notification Plugin demo app.
// Registers the native content fetcher SPI implementation.
//
// @author Matthew Raymer
// @version 1.0.0
// @created 2025-11-04
//
import UIKit
import Capacitor
/**
* Application delegate for Daily Notification Plugin demo app
* Equivalent to PluginApplication.java on Android
*/
@main
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
// Initialize Daily Notification Plugin demo fetcher
// Note: This is called before Capacitor bridge is initialized
// Plugin registration happens in ViewController
print("AppDelegate: Initializing Daily Notification Plugin demo app")
return true
}
func applicationWillResignActive(_ application: UIApplication) {
// Pause ongoing tasks
}
func applicationDidEnterBackground(_ application: UIApplication) {
// Release resources when app enters background
}
func applicationWillEnterForeground(_ application: UIApplication) {
// Restore resources when app enters foreground
}
func applicationDidBecomeActive(_ application: UIApplication) {
// Restart paused tasks
}
func applicationWillTerminate(_ application: UIApplication) {
// Save data before app terminates
}
// MARK: - URL Scheme Handling
func application(
_ app: UIApplication,
open url: URL,
options: [UIApplication.OpenURLOptionsKey: Any] = [:]
) -> Bool {
// Handle URL schemes (e.g., deep links)
return ApplicationDelegateProxy.shared.application(app, open: url, options: options)
}
// MARK: - Universal Links
func application(
_ application: UIApplication,
continue userActivity: NSUserActivity,
restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void
) -> Bool {
// Handle universal links
return ApplicationDelegateProxy.shared.application(
application,
continue: userActivity,
restorationHandler: restorationHandler
)
}
// MARK: - Push Notifications
func application(
_ application: UIApplication,
didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data
) {
// Handle device token registration
NotificationCenter.default.post(
name: Notification.Name("didRegisterForRemoteNotifications"),
object: nil,
userInfo: ["deviceToken": deviceToken]
)
}
func application(
_ application: UIApplication,
didFailToRegisterForRemoteNotificationsWithError error: Error
) {
// Handle registration failure
print("AppDelegate: Failed to register for remote notifications: \(error)")
}
}

119
ios/App/App/Info.plist

@ -0,0 +1,119 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<!-- App Display Name -->
<key>CFBundleDisplayName</key>
<string>DailyNotification Test</string>
<!-- Bundle Identifier -->
<key>CFBundleIdentifier</key>
<string>com.timesafari.dailynotification</string>
<!-- Bundle Name -->
<key>CFBundleName</key>
<string>DailyNotification Test App</string>
<!-- Version -->
<key>CFBundleShortVersionString</key>
<string>1.0.0</string>
<!-- Build Number -->
<key>CFBundleVersion</key>
<string>1</string>
<!-- Minimum iOS Version -->
<key>LSMinimumSystemVersion</key>
<string>13.0</string>
<!-- Device Family -->
<key>UIDeviceFamily</key>
<array>
<integer>1</integer>
<integer>2</integer>
</array>
<!-- Supported Interface Orientations -->
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<!-- Supported Interface Orientations (iPad) -->
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<!-- Status Bar Style -->
<key>UIStatusBarStyle</key>
<string>UIStatusBarStyleDefault</string>
<!-- Status Bar Hidden -->
<key>UIStatusBarHidden</key>
<false/>
<!-- Launch Screen -->
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<!-- Privacy Usage Descriptions -->
<key>NSUserNotificationsUsageDescription</key>
<string>This app uses notifications to deliver daily updates and reminders.</string>
<!-- Background Modes -->
<key>UIBackgroundModes</key>
<array>
<string>background-fetch</string>
<string>background-processing</string>
<string>remote-notification</string>
</array>
<!-- Background Task Identifiers -->
<key>BGTaskSchedulerPermittedIdentifiers</key>
<array>
<string>com.timesafari.dailynotification.fetch</string>
<string>com.timesafari.dailynotification.notify</string>
</array>
<!-- App Transport Security -->
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<false/>
<key>NSExceptionDomains</key>
<dict>
<!-- Add your callback domains here -->
</dict>
</dict>
<!-- Scene Configuration (iOS 13+) -->
<key>UIApplicationSceneManifest</key>
<dict>
<key>UIApplicationSupportsMultipleScenes</key>
<false/>
<key>UISceneConfigurations</key>
<dict>
<key>UIWindowSceneSessionRoleApplication</key>
<array>
<dict>
<key>UISceneConfigurationName</key>
<string>Default Configuration</string>
<key>UISceneDelegateClassName</key>
<string>$(PRODUCT_MODULE_NAME).SceneDelegate</string>
</dict>
</array>
</dict>
</dict>
<!-- Background App Refresh -->
<key>UIApplicationExitsOnSuspend</key>
<false/>
</dict>
</plist>

61
ios/App/App/SceneDelegate.swift

@ -0,0 +1,61 @@
//
// SceneDelegate.swift
// DailyNotification Test App
//
// Scene delegate for iOS 13+ scene-based lifecycle.
// Handles scene creation and lifecycle events.
//
// @author Matthew Raymer
// @version 1.0.0
// @created 2025-11-04
//
import UIKit
/**
* Scene delegate for iOS 13+ scene-based lifecycle
* Required for modern iOS apps using scene-based architecture
*/
@available(iOS 13.0, *)
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
func scene(
_ scene: UIScene,
willConnectTo session: UISceneSession,
options connectionOptions: UIScene.ConnectionOptions
) {
// Called when a new scene session is being created
guard let windowScene = (scene as? UIWindowScene) else { return }
let window = UIWindow(windowScene: windowScene)
self.window = window
// Create and configure the view controller
let viewController = ViewController()
window.rootViewController = viewController
window.makeKeyAndVisible()
}
func sceneDidDisconnect(_ scene: UIScene) {
// Called when the scene is being released by the system
}
func sceneDidBecomeActive(_ scene: UIScene) {
// Called when the scene has moved from inactive to active state
}
func sceneWillResignActive(_ scene: UIScene) {
// Called when the scene will move from active to inactive state
}
func sceneWillEnterForeground(_ scene: UIScene) {
// Called when the scene is about to move from background to foreground
}
func sceneDidEnterBackground(_ scene: UIScene) {
// Called when the scene has moved from background to foreground
}
}

69
ios/App/App/ViewController.swift

@ -0,0 +1,69 @@
//
// ViewController.swift
// DailyNotification Test App
//
// Main view controller for the Daily Notification Plugin demo app.
// Equivalent to MainActivity.java on Android - extends Capacitor's bridge.
//
// @author Matthew Raymer
// @version 1.0.0
// @created 2025-11-04
//
import UIKit
import Capacitor
/**
* Main view controller extending Capacitor's bridge view controller
* Equivalent to MainActivity extends BridgeActivity on Android
*/
class ViewController: CAPBridgeViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Initialize Daily Notification Plugin demo fetcher
// This is called after Capacitor bridge is initialized
initializePlugin()
}
/**
* Initialize plugin and register native fetcher
* Equivalent to PluginApplication.onCreate() on Android
*/
private func initializePlugin() {
print("ViewController: Initializing Daily Notification Plugin")
// Note: Plugin registration happens automatically via Capacitor
// Native fetcher registration can be done here if needed
// Example: Register demo native fetcher (if implementing SPI)
// DailyNotificationPlugin.setNativeFetcher(DemoNativeFetcher())
print("ViewController: Daily Notification Plugin initialized")
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
}
override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)
}
// MARK: - Memory Management
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated
}
}

638
ios/App/App/public/index.html

@ -3,6 +3,9 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="viewport-fit=cover, width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Expires" content="0">
<title>DailyNotification Plugin Test</title>
<style>
body {
@ -14,98 +17,627 @@
color: white;
}
.container {
max-width: 600px;
max-width: 800px;
margin: 0 auto;
text-align: center;
}
h1 {
text-align: center;
margin-bottom: 30px;
font-size: 2.5em;
}
.section {
background: rgba(255, 255, 255, 0.1);
border-radius: 10px;
padding: 20px;
margin: 20px 0;
}
.section h2 {
margin-top: 0;
color: #ffd700;
}
.button {
background: rgba(255, 255, 255, 0.2);
border: 2px solid rgba(255, 255, 255, 0.3);
color: white;
padding: 15px 30px;
margin: 10px;
border-radius: 25px;
padding: 12px 24px;
margin: 8px;
border-radius: 20px;
cursor: pointer;
font-size: 16px;
font-size: 14px;
transition: all 0.3s ease;
display: inline-block;
}
.button:hover {
background: rgba(255, 255, 255, 0.3);
transform: translateY(-2px);
}
.button:disabled {
opacity: 0.5;
cursor: not-allowed;
transform: none;
}
.status {
margin-top: 30px;
padding: 20px;
background: rgba(255, 255, 255, 0.1);
border-radius: 10px;
margin-top: 15px;
padding: 15px;
background: rgba(0, 0, 0, 0.2);
border-radius: 8px;
font-family: monospace;
font-size: 12px;
white-space: pre-wrap;
max-height: 200px;
overflow-y: auto;
}
.success { color: #4CAF50; }
.error { color: #f44336; }
.warning { color: #ff9800; }
.info { color: #2196F3; }
.grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 15px;
margin: 15px 0;
}
.input-group {
margin: 10px 0;
}
.input-group label {
display: block;
margin-bottom: 5px;
font-weight: bold;
}
.input-group input, .input-group select {
width: 100%;
padding: 8px;
border-radius: 5px;
border: 1px solid rgba(255, 255, 255, 0.3);
background: rgba(255, 255, 255, 0.1);
color: white;
}
.input-group input::placeholder {
color: rgba(255, 255, 255, 0.7);
}
</style>
</head>
<body>
<div class="container">
<h1>🔔 DailyNotification Plugin Test</h1>
<p>Test the DailyNotification plugin functionality</p>
<button class="button" onclick="testPlugin()">Test Plugin</button>
<button class="button" onclick="configurePlugin()">Configure Plugin</button>
<button class="button" onclick="checkStatus()">Check Status</button>
<div id="status" class="status">
Ready to test...
<!-- Plugin Status Section -->
<div class="section">
<h2>📊 Plugin Status</h2>
<div class="grid">
<button class="button" onclick="checkPluginAvailability()">Check Availability</button>
<button class="button" onclick="getNotificationStatus()">Get Status</button>
<button class="button" onclick="checkPermissions()">Check Permissions</button>
<button class="button" onclick="getBatteryStatus()">Battery Status</button>
</div>
<div id="status" class="status">Ready to test...</div>
</div>
</div>
<script type="module">
import { Capacitor } from '@capacitor/core';
import { DailyNotification } from '@timesafari/daily-notification-plugin';
<!-- Permission Management Section -->
<div class="section">
<h2>🔐 Permission Management</h2>
<div class="grid">
<button class="button" onclick="requestPermissions()">Request Permissions</button>
<button class="button" onclick="requestExactAlarmPermission()">Request Exact Alarm</button>
<button class="button" onclick="openExactAlarmSettings()">Open Settings</button>
<button class="button" onclick="requestBatteryOptimizationExemption()">Battery Exemption</button>
</div>
</div>
window.Capacitor = Capacitor;
window.DailyNotification = DailyNotification;
<!-- Notification Scheduling Section -->
<div class="section">
<h2>⏰ Notification Scheduling</h2>
<div class="input-group">
<label for="notificationUrl">Content URL:</label>
<input type="text" id="notificationUrl" placeholder="https://api.example.com/daily-content" value="https://api.example.com/daily-content">
</div>
<div class="input-group">
<label for="notificationTime">Schedule Time:</label>
<input type="time" id="notificationTime" value="09:00">
</div>
<div class="input-group">
<label for="notificationTitle">Title:</label>
<input type="text" id="notificationTitle" placeholder="Daily Notification" value="Daily Notification">
</div>
<div class="input-group">
<label for="notificationBody">Body:</label>
<input type="text" id="notificationBody" placeholder="Your daily content is ready!" value="Your daily content is ready!">
</div>
<div class="grid">
<button class="button" onclick="scheduleNotification()">Schedule Notification</button>
<button class="button" onclick="cancelAllNotifications()">Cancel All</button>
<button class="button" onclick="getLastNotification()">Get Last</button>
</div>
</div>
window.testPlugin = async function() {
const status = document.getElementById('status');
status.innerHTML = 'Testing plugin...';
<!-- Configuration Section -->
<div class="section">
<h2>⚙️ Plugin Configuration</h2>
<div class="input-group">
<label for="configUrl">Fetch URL:</label>
<input type="text" id="configUrl" placeholder="https://api.example.com/content" value="https://api.example.com/content">
</div>
<div class="input-group">
<label for="configTime">Schedule Time:</label>
<input type="time" id="configTime" value="09:00">
</div>
<div class="input-group">
<label for="configRetryCount">Retry Count:</label>
<input type="number" id="configRetryCount" value="3" min="0" max="10">
</div>
<div class="grid">
<button class="button" onclick="configurePlugin()">Configure Plugin</button>
<button class="button" onclick="updateSettings()">Update Settings</button>
</div>
</div>
<!-- Advanced Features Section -->
<div class="section">
<h2>🚀 Advanced Features</h2>
<div class="grid">
<button class="button" onclick="getExactAlarmStatus()">Exact Alarm Status</button>
<button class="button" onclick="getRebootRecoveryStatus()">Reboot Recovery</button>
<button class="button" onclick="getRollingWindowStats()">Rolling Window</button>
<button class="button" onclick="maintainRollingWindow()">Maintain Window</button>
<button class="button" onclick="getContentCache()">Content Cache</button>
<button class="button" onclick="clearContentCache()">Clear Cache</button>
<button class="button" onclick="getContentHistory()">Content History</button>
<button class="button" onclick="getDualScheduleStatus()">Dual Schedule</button>
</div>
</div>
</div>
<script>
console.log('🔔 DailyNotification Plugin Test Interface Loading...');
// Global variables
let plugin = null;
let isPluginAvailable = false;
// Initialize plugin on page load
document.addEventListener('DOMContentLoaded', async function() {
console.log('📱 DOM loaded, initializing plugin...');
await initializePlugin();
});
// Initialize the real DailyNotification plugin
async function initializePlugin() {
try {
// Plugin is loaded and ready
status.innerHTML = 'Plugin is loaded and ready!';
// Try to access the real plugin through Capacitor
if (window.Capacitor && window.Capacitor.Plugins && window.Capacitor.Plugins.DailyNotification) {
plugin = window.Capacitor.Plugins.DailyNotification;
isPluginAvailable = true;
console.log('✅ Real DailyNotification plugin found!');
updateStatus('success', '✅ Real DailyNotification plugin loaded successfully!');
} else {
// Fallback to mock for development
console.log('⚠️ Real plugin not available, using mock for development');
plugin = createMockPlugin();
isPluginAvailable = false;
updateStatus('warning', '⚠️ Using mock plugin (real plugin not available)');
}
} catch (error) {
status.innerHTML = `Plugin test failed: ${error.message}`;
console.error('❌ Plugin initialization failed:', error);
updateStatus('error', `❌ Plugin initialization failed: ${error.message}`);
}
};
window.configurePlugin = async function() {
const status = document.getElementById('status');
status.innerHTML = 'Configuring plugin...';
}
// Create mock plugin for development/testing
function createMockPlugin() {
return {
configure: async (options) => {
console.log('Mock configure called with:', options);
return Promise.resolve();
},
getNotificationStatus: async () => {
return Promise.resolve({
isEnabled: true,
isScheduled: true,
lastNotificationTime: Date.now() - 86400000,
nextNotificationTime: Date.now() + 3600000,
pending: 1,
settings: { url: 'https://api.example.com/content', time: '09:00' },
error: null
});
},
checkPermissions: async () => {
return Promise.resolve({
notifications: 'granted',
backgroundRefresh: 'granted',
alert: true,
badge: true,
sound: true
});
},
requestPermissions: async () => {
return Promise.resolve({
notifications: 'granted',
backgroundRefresh: 'granted',
alert: true,
badge: true,
sound: true
});
},
scheduleDailyNotification: async (options) => {
console.log('Mock scheduleDailyNotification called with:', options);
return Promise.resolve();
},
cancelAllNotifications: async () => {
console.log('Mock cancelAllNotifications called');
return Promise.resolve();
},
getLastNotification: async () => {
return Promise.resolve({
id: 'mock-123',
title: 'Mock Notification',
body: 'This is a mock notification',
timestamp: Date.now() - 3600000,
url: 'https://example.com'
});
},
getBatteryStatus: async () => {
return Promise.resolve({
level: 85,
isCharging: false,
powerState: 1,
isOptimizationExempt: false
});
},
getExactAlarmStatus: async () => {
return Promise.resolve({
supported: true,
enabled: true,
canSchedule: true,
fallbackWindow: '±15 minutes'
});
},
requestExactAlarmPermission: async () => {
console.log('Mock requestExactAlarmPermission called');
return Promise.resolve();
},
openExactAlarmSettings: async () => {
console.log('Mock openExactAlarmSettings called');
return Promise.resolve();
},
requestBatteryOptimizationExemption: async () => {
console.log('Mock requestBatteryOptimizationExemption called');
return Promise.resolve();
},
getRebootRecoveryStatus: async () => {
return Promise.resolve({
inProgress: false,
lastRecoveryTime: Date.now() - 86400000,
timeSinceLastRecovery: 86400000,
recoveryNeeded: false
});
},
getRollingWindowStats: async () => {
return Promise.resolve({
stats: 'Window: 7 days, Notifications: 5, Success rate: 100%',
maintenanceNeeded: false,
timeUntilNextMaintenance: 3600000
});
},
maintainRollingWindow: async () => {
console.log('Mock maintainRollingWindow called');
return Promise.resolve();
},
getContentCache: async () => {
return Promise.resolve({
'cache-key-1': { content: 'Mock cached content', timestamp: Date.now() },
'cache-key-2': { content: 'Another mock item', timestamp: Date.now() - 3600000 }
});
},
clearContentCache: async () => {
console.log('Mock clearContentCache called');
return Promise.resolve();
},
getContentHistory: async () => {
return Promise.resolve([
{ id: '1', timestamp: Date.now() - 86400000, success: true, content: 'Mock content 1' },
{ id: '2', timestamp: Date.now() - 172800000, success: true, content: 'Mock content 2' }
]);
},
getDualScheduleStatus: async () => {
return Promise.resolve({
isActive: true,
contentSchedule: { nextRun: Date.now() + 3600000, isEnabled: true },
userSchedule: { nextRun: Date.now() + 7200000, isEnabled: true },
lastContentFetch: Date.now() - 3600000,
lastUserNotification: Date.now() - 7200000
});
}
};
}
// Utility function to update status display
function updateStatus(type, message) {
const statusEl = document.getElementById('status');
statusEl.className = `status ${type}`;
statusEl.textContent = message;
console.log(`[${type.toUpperCase()}] ${message}`);
}
// Plugin availability check
async function checkPluginAvailability() {
updateStatus('info', '🔍 Checking plugin availability...');
try {
await DailyNotification.configure({
fetchUrl: 'https://api.example.com/daily-content',
scheduleTime: '09:00',
enableNotifications: true
});
status.innerHTML = 'Plugin configured successfully!';
if (plugin) {
updateStatus('success', `✅ Plugin available: ${isPluginAvailable ? 'Real plugin' : 'Mock plugin'}`);
} else {
updateStatus('error', '❌ Plugin not available');
}
} catch (error) {
status.innerHTML = `Configuration failed: ${error.message}`;
updateStatus('error', `❌ Availability check failed: ${error.message}`);
}
};
window.checkStatus = async function() {
const status = document.getElementById('status');
status.innerHTML = 'Checking plugin status...';
}
// Get notification status
async function getNotificationStatus() {
updateStatus('info', '📊 Getting notification status...');
try {
const status = await plugin.getNotificationStatus();
updateStatus('success', `📊 Status: ${JSON.stringify(status, null, 2)}`);
} catch (error) {
updateStatus('error', `❌ Status check failed: ${error.message}`);
}
}
// Check permissions
async function checkPermissions() {
updateStatus('info', '🔐 Checking permissions...');
try {
const result = await DailyNotification.getStatus();
status.innerHTML = `Plugin status: ${JSON.stringify(result, null, 2)}`;
const permissions = await plugin.checkPermissions();
updateStatus('success', `🔐 Permissions: ${JSON.stringify(permissions, null, 2)}`);
} catch (error) {
status.innerHTML = `Status check failed: ${error.message}`;
updateStatus('error', `❌ Permission check failed: ${error.message}`);
}
};
}
// Request permissions
async function requestPermissions() {
updateStatus('info', '🔐 Requesting permissions...');
try {
const result = await plugin.requestPermissions();
updateStatus('success', `🔐 Permission result: ${JSON.stringify(result, null, 2)}`);
} catch (error) {
updateStatus('error', `❌ Permission request failed: ${error.message}`);
}
}
// Get battery status
async function getBatteryStatus() {
updateStatus('info', '🔋 Getting battery status...');
try {
const battery = await plugin.getBatteryStatus();
updateStatus('success', `🔋 Battery: ${JSON.stringify(battery, null, 2)}`);
} catch (error) {
updateStatus('error', `❌ Battery check failed: ${error.message}`);
}
}
// Schedule notification
async function scheduleNotification() {
updateStatus('info', '⏰ Scheduling notification...');
try {
const timeInput = document.getElementById('notificationTime').value;
const [hours, minutes] = timeInput.split(':');
const now = new Date();
const scheduledTime = new Date();
scheduledTime.setHours(parseInt(hours), parseInt(minutes), 0, 0);
// If scheduled time is in the past, schedule for tomorrow
if (scheduledTime <= now) {
scheduledTime.setDate(scheduledTime.getDate() + 1);
}
// Calculate prefetch time (5 minutes before notification)
const prefetchTime = new Date(scheduledTime.getTime() - 300000); // 5 minutes
const prefetchTimeReadable = prefetchTime.toLocaleTimeString();
const notificationTimeReadable = scheduledTime.toLocaleTimeString();
const prefetchTimeString = prefetchTime.getHours().toString().padStart(2, '0') + ':' +
prefetchTime.getMinutes().toString().padStart(2, '0');
const notificationTimeString = scheduledTime.getHours().toString().padStart(2, '0') + ':' +
scheduledTime.getMinutes().toString().padStart(2, '0');
const options = {
url: document.getElementById('notificationUrl').value,
time: timeInput,
title: document.getElementById('notificationTitle').value,
body: document.getElementById('notificationBody').value,
sound: true,
priority: 'high'
};
await plugin.scheduleDailyNotification(options);
updateStatus('success', `✅ Notification scheduled!<br>` +
`📥 Prefetch: ${prefetchTimeReadable} (${prefetchTimeString})<br>` +
`🔔 Notification: ${notificationTimeReadable} (${notificationTimeString})`);
} catch (error) {
updateStatus('error', `❌ Scheduling failed: ${error.message}`);
}
}
// Cancel all notifications
async function cancelAllNotifications() {
updateStatus('info', '❌ Cancelling all notifications...');
try {
await plugin.cancelAllNotifications();
updateStatus('success', '❌ All notifications cancelled');
} catch (error) {
updateStatus('error', `❌ Cancel failed: ${error.message}`);
}
}
// Get last notification
async function getLastNotification() {
updateStatus('info', '📱 Getting last notification...');
try {
const notification = await plugin.getLastNotification();
updateStatus('success', `📱 Last notification: ${JSON.stringify(notification, null, 2)}`);
} catch (error) {
updateStatus('error', `❌ Get last notification failed: ${error.message}`);
}
}
// Configure plugin
async function configurePlugin() {
updateStatus('info', '⚙️ Configuring plugin...');
try {
const config = {
fetchUrl: document.getElementById('configUrl').value,
scheduleTime: document.getElementById('configTime').value,
retryCount: parseInt(document.getElementById('configRetryCount').value),
enableNotifications: true,
offlineFallback: true
};
await plugin.configure(config);
updateStatus('success', `⚙️ Plugin configured: ${JSON.stringify(config, null, 2)}`);
} catch (error) {
updateStatus('error', `❌ Configuration failed: ${error.message}`);
}
}
// Update settings
async function updateSettings() {
updateStatus('info', '⚙️ Updating settings...');
try {
const settings = {
url: document.getElementById('configUrl').value,
time: document.getElementById('configTime').value,
retryCount: parseInt(document.getElementById('configRetryCount').value),
sound: true,
priority: 'high'
};
await plugin.updateSettings(settings);
updateStatus('success', `⚙️ Settings updated: ${JSON.stringify(settings, null, 2)}`);
} catch (error) {
updateStatus('error', `❌ Settings update failed: ${error.message}`);
}
}
// Get exact alarm status
async function getExactAlarmStatus() {
updateStatus('info', '⏰ Getting exact alarm status...');
try {
const status = await plugin.getExactAlarmStatus();
updateStatus('success', `⏰ Exact alarm status: ${JSON.stringify(status, null, 2)}`);
} catch (error) {
updateStatus('error', `❌ Exact alarm check failed: ${error.message}`);
}
}
// Request exact alarm permission
async function requestExactAlarmPermission() {
updateStatus('info', '⏰ Requesting exact alarm permission...');
try {
await plugin.requestExactAlarmPermission();
updateStatus('success', '⏰ Exact alarm permission requested');
} catch (error) {
updateStatus('error', `❌ Exact alarm permission request failed: ${error.message}`);
}
}
// Open exact alarm settings
async function openExactAlarmSettings() {
updateStatus('info', '⚙️ Opening exact alarm settings...');
try {
await plugin.openExactAlarmSettings();
updateStatus('success', '⚙️ Exact alarm settings opened');
} catch (error) {
updateStatus('error', `❌ Open settings failed: ${error.message}`);
}
}
// Request battery optimization exemption
async function requestBatteryOptimizationExemption() {
updateStatus('info', '🔋 Requesting battery optimization exemption...');
try {
await plugin.requestBatteryOptimizationExemption();
updateStatus('success', '🔋 Battery optimization exemption requested');
} catch (error) {
updateStatus('error', `❌ Battery exemption request failed: ${error.message}`);
}
}
// Get reboot recovery status
async function getRebootRecoveryStatus() {
updateStatus('info', '🔄 Getting reboot recovery status...');
try {
const status = await plugin.getRebootRecoveryStatus();
updateStatus('success', `🔄 Reboot recovery status: ${JSON.stringify(status, null, 2)}`);
} catch (error) {
updateStatus('error', `❌ Reboot recovery check failed: ${error.message}`);
}
}
// Get rolling window stats
async function getRollingWindowStats() {
updateStatus('info', '📊 Getting rolling window stats...');
try {
const stats = await plugin.getRollingWindowStats();
updateStatus('success', `📊 Rolling window stats: ${JSON.stringify(stats, null, 2)}`);
} catch (error) {
updateStatus('error', `❌ Rolling window stats failed: ${error.message}`);
}
}
// Maintain rolling window
async function maintainRollingWindow() {
updateStatus('info', '🔧 Maintaining rolling window...');
try {
await plugin.maintainRollingWindow();
updateStatus('success', '🔧 Rolling window maintenance completed');
} catch (error) {
updateStatus('error', `❌ Rolling window maintenance failed: ${error.message}`);
}
}
// Get content cache
async function getContentCache() {
updateStatus('info', '💾 Getting content cache...');
try {
const cache = await plugin.getContentCache();
updateStatus('success', `💾 Content cache: ${JSON.stringify(cache, null, 2)}`);
} catch (error) {
updateStatus('error', `❌ Content cache check failed: ${error.message}`);
}
}
// Clear content cache
async function clearContentCache() {
updateStatus('info', '🗑️ Clearing content cache...');
try {
await plugin.clearContentCache();
updateStatus('success', '🗑️ Content cache cleared');
} catch (error) {
updateStatus('error', `❌ Clear cache failed: ${error.message}`);
}
}
// Get content history
async function getContentHistory() {
updateStatus('info', '📚 Getting content history...');
try {
const history = await plugin.getContentHistory();
updateStatus('success', `📚 Content history: ${JSON.stringify(history, null, 2)}`);
} catch (error) {
updateStatus('error', `❌ Content history check failed: ${error.message}`);
}
}
// Get dual schedule status
async function getDualScheduleStatus() {
updateStatus('info', '🔄 Getting dual schedule status...');
try {
const status = await plugin.getDualScheduleStatus();
updateStatus('success', `🔄 Dual schedule status: ${JSON.stringify(status, null, 2)}`);
} catch (error) {
updateStatus('error', `❌ Dual schedule check failed: ${error.message}`);
}
}
console.log('🔔 DailyNotification Plugin Test Interface Loaded Successfully!');
</script>
</body>
</html>

4
ios/DailyNotificationPlugin.podspec

@ -8,8 +8,8 @@ Pod::Spec.new do |s|
s.source = { :git => 'https://github.com/timesafari/daily-notification-plugin.git', :tag => s.version.to_s }
s.source_files = 'Plugin/**/*.{swift,h,m,c,cc,mm,cpp}'
s.ios.deployment_target = '13.0'
s.dependency 'Capacitor', '~> 5.0.0'
s.dependency 'CapacitorCordova', '~> 5.0.0'
s.dependency 'Capacitor', '~> 6.0'
s.dependency 'CapacitorCordova', '~> 6.0'
s.swift_version = '5.1'
s.xcconfig = { 'GCC_PREPROCESSOR_DEFINITIONS' => '$(inherited) COCOAPODS=1' }
s.deprecated = false

28
ios/Plugin/DailyNotificationBackgroundTaskManager.swift

@ -292,11 +292,17 @@ class DailyNotificationBackgroundTaskManager {
// Parse new content
let newContent = try JSONSerialization.jsonObject(with: data) as? [String: Any]
// Update notification with new content
var updatedNotification = notification
updatedNotification.payload = newContent
updatedNotification.fetchedAt = Date().timeIntervalSince1970 * 1000
updatedNotification.etag = response.allHeaderFields["ETag"] as? String
// Create new notification instance with updated content
let updatedNotification = NotificationContent(
id: notification.id,
title: notification.title,
body: notification.body,
scheduledTime: notification.scheduledTime,
fetchedAt: Date().timeIntervalSince1970 * 1000,
url: notification.url,
payload: newContent,
etag: response.allHeaderFields["ETag"] as? String
)
// Check TTL before storing
if ttlEnforcer.validateBeforeArming(updatedNotification) {
@ -335,8 +341,16 @@ class DailyNotificationBackgroundTaskManager {
// Update ETag if provided
if let etag = response.allHeaderFields["ETag"] as? String {
var updatedNotification = notification
updatedNotification.etag = etag
let updatedNotification = NotificationContent(
id: notification.id,
title: notification.title,
body: notification.body,
scheduledTime: notification.scheduledTime,
fetchedAt: notification.fetchedAt,
url: notification.url,
payload: notification.payload,
etag: etag
)
storeUpdatedContent(updatedNotification) { success in
completion(success)
}

6
ios/Plugin/DailyNotificationBackgroundTasks.swift

@ -21,7 +21,7 @@ import CoreData
*/
extension DailyNotificationPlugin {
private func handleBackgroundFetch(task: BGAppRefreshTask) {
func handleBackgroundFetch(task: BGAppRefreshTask) {
print("DNP-FETCH-START: Background fetch task started")
task.expirationHandler = {
@ -52,7 +52,7 @@ extension DailyNotificationPlugin {
}
}
private func handleBackgroundNotify(task: BGProcessingTask) {
func handleBackgroundNotify(task: BGProcessingTask) {
print("DNP-NOTIFY-START: Background notify task started")
task.expirationHandler = {
@ -124,7 +124,7 @@ extension DailyNotificationPlugin {
print("DNP-CACHE-STORE: Content stored in Core Data")
}
private func getLatestContent() async throws -> [String: Any]? {
func getLatestContent() async throws -> [String: Any]? {
let context = persistenceController.container.viewContext
let request: NSFetchRequest<ContentCache> = ContentCache.fetchRequest()
request.sortDescriptors = [NSSortDescriptor(keyPath: \ContentCache.fetchedAt, ascending: false)]

5
ios/Plugin/DailyNotificationCallbacks.swift

@ -7,6 +7,7 @@
//
import Foundation
import Capacitor
import CoreData
/**
@ -108,7 +109,7 @@ extension DailyNotificationPlugin {
// MARK: - Private Callback Implementation
private func fireCallbacks(eventType: String, payload: [String: Any]) async throws {
func fireCallbacks(eventType: String, payload: [String: Any]) async throws {
// Get registered callbacks from Core Data
let context = persistenceController.container.viewContext
let request: NSFetchRequest<Callback> = Callback.fetchRequest()
@ -246,7 +247,7 @@ extension DailyNotificationPlugin {
}
}
private func getHealthStatus() async throws -> [String: Any] {
func getHealthStatus() async throws -> [String: Any] {
let context = persistenceController.container.viewContext
// Get next runs (simplified)

79
ios/Plugin/DailyNotificationETagManager.swift

@ -69,7 +69,7 @@ class DailyNotificationETagManager {
// Load ETag cache from storage
loadETagCache()
logger.debug(TAG, "ETagManager initialized with \(etagCache.count) cached ETags")
logger.log(.debug, "ETagManager initialized with \(etagCache.count) cached ETags")
}
// MARK: - ETag Cache Management
@ -79,14 +79,14 @@ class DailyNotificationETagManager {
*/
private func loadETagCache() {
do {
logger.debug(TAG, "Loading ETag cache from storage")
logger.log(.debug, "Loading ETag cache from storage")
// This would typically load from SQLite or UserDefaults
// For now, we'll start with an empty cache
logger.debug(TAG, "ETag cache loaded from storage")
logger.log(.debug, "ETag cache loaded from storage")
} catch {
logger.error(TAG, "Error loading ETag cache: \(error)")
logger.log(.error, "Error loading ETag cache: \(error)")
}
}
@ -95,14 +95,14 @@ class DailyNotificationETagManager {
*/
private func saveETagCache() {
do {
logger.debug(TAG, "Saving ETag cache to storage")
logger.log(.debug, "Saving ETag cache to storage")
// This would typically save to SQLite or UserDefaults
// For now, we'll just log the action
logger.debug(TAG, "ETag cache saved to storage")
logger.log(.debug, "ETag cache saved to storage")
} catch {
logger.error(TAG, "Error saving ETag cache: \(error)")
logger.log(.error, "Error saving ETag cache: \(error)")
}
}
@ -130,7 +130,7 @@ class DailyNotificationETagManager {
*/
func setETag(for url: String, etag: String) {
do {
logger.debug(TAG, "Setting ETag for \(url): \(etag)")
logger.log(.debug, "Setting ETag for \(url): \(etag)")
let info = ETagInfo(etag: etag, timestamp: Date())
@ -139,10 +139,10 @@ class DailyNotificationETagManager {
self.saveETagCache()
}
logger.debug(TAG, "ETag set successfully")
logger.log(.debug, "ETag set successfully")
} catch {
logger.error(TAG, "Error setting ETag: \(error)")
logger.log(.error, "Error setting ETag: \(error)")
}
}
@ -153,17 +153,17 @@ class DailyNotificationETagManager {
*/
func removeETag(for url: String) {
do {
logger.debug(TAG, "Removing ETag for \(url)")
logger.log(.debug, "Removing ETag for \(url)")
cacheQueue.async(flags: .barrier) {
self.etagCache.removeValue(forKey: url)
self.saveETagCache()
}
logger.debug(TAG, "ETag removed successfully")
logger.log(.debug, "ETag removed successfully")
} catch {
logger.error(TAG, "Error removing ETag: \(error)")
logger.log(.error, "Error removing ETag: \(error)")
}
}
@ -172,17 +172,17 @@ class DailyNotificationETagManager {
*/
func clearETags() {
do {
logger.debug(TAG, "Clearing all ETags")
logger.log(.debug, "Clearing all ETags")
cacheQueue.async(flags: .barrier) {
self.etagCache.removeAll()
self.saveETagCache()
}
logger.debug(TAG, "All ETags cleared")
logger.log(.debug, "All ETags cleared")
} catch {
logger.error(TAG, "Error clearing ETags: \(error)")
logger.log(.error, "Error clearing ETags: \(error)")
}
}
@ -196,7 +196,7 @@ class DailyNotificationETagManager {
*/
func makeConditionalRequest(to url: String) -> ConditionalRequestResult {
do {
logger.debug(TAG, "Making conditional request to \(url)")
logger.log(.debug, "Making conditional request to \(url)")
// Get cached ETag
let etag = getETag(for: url)
@ -212,16 +212,33 @@ class DailyNotificationETagManager {
// Set conditional headers
if let etag = etag {
request.setValue(etag, forHTTPHeaderField: DailyNotificationETagManager.HEADER_IF_NONE_MATCH)
logger.debug(TAG, "Added If-None-Match header: \(etag)")
logger.log(.debug, "Added If-None-Match header: \(etag)")
}
// Set user agent
request.setValue("DailyNotificationPlugin/1.0.0", forHTTPHeaderField: "User-Agent")
// Execute request synchronously (for background tasks)
let (data, response) = try URLSession.shared.data(for: request)
let semaphore = DispatchSemaphore(value: 0)
var resultData: Data?
var resultResponse: URLResponse?
var resultError: Error?
URLSession.shared.dataTask(with: request) { data, response, error in
resultData = data
resultResponse = response
resultError = error
semaphore.signal()
}.resume()
_ = semaphore.wait(timeout: .now() + DailyNotificationETagManager.REQUEST_TIMEOUT_SECONDS)
if let error = resultError {
throw error
}
guard let httpResponse = response as? HTTPURLResponse else {
guard let data = resultData,
let httpResponse = resultResponse as? HTTPURLResponse else {
return ConditionalRequestResult.error("Invalid response type")
}
@ -231,12 +248,12 @@ class DailyNotificationETagManager {
// Update metrics
metrics.recordRequest(url: url, responseCode: httpResponse.statusCode, fromCache: result.isFromCache)
logger.info(TAG, "Conditional request completed: \(httpResponse.statusCode) (cached: \(result.isFromCache))")
logger.log(.info, "Conditional request completed: \(httpResponse.statusCode) (cached: \(result.isFromCache))")
return result
} catch {
logger.error(TAG, "Error making conditional request: \(error)")
logger.log(.error, "Error making conditional request: \(error)")
metrics.recordError(url: url, error: error.localizedDescription)
return ConditionalRequestResult.error(error.localizedDescription)
}
@ -254,20 +271,20 @@ class DailyNotificationETagManager {
do {
switch response.statusCode {
case DailyNotificationETagManager.HTTP_NOT_MODIFIED:
logger.debug(TAG, "304 Not Modified - using cached content")
logger.log(.debug, "304 Not Modified - using cached content")
return ConditionalRequestResult.notModified()
case DailyNotificationETagManager.HTTP_OK:
logger.debug(TAG, "200 OK - new content available")
logger.log(.debug, "200 OK - new content available")
return handleOKResponse(response, data: data, url: url)
default:
logger.warning(TAG, "Unexpected response code: \(response.statusCode)")
logger.log(.warning, "Unexpected response code: \(response.statusCode)")
return ConditionalRequestResult.error("Unexpected response code: \(response.statusCode)")
}
} catch {
logger.error(TAG, "Error handling response: \(error)")
logger.log(.error, "Error handling response: \(error)")
return ConditionalRequestResult.error(error.localizedDescription)
}
}
@ -298,7 +315,7 @@ class DailyNotificationETagManager {
return ConditionalRequestResult.success(content: content, etag: newETag)
} catch {
logger.error(TAG, "Error handling OK response: \(error)")
logger.log(.error, "Error handling OK response: \(error)")
return ConditionalRequestResult.error(error.localizedDescription)
}
}
@ -319,7 +336,7 @@ class DailyNotificationETagManager {
*/
func resetMetrics() {
metrics.reset()
logger.debug(TAG, "Network metrics reset")
logger.log(.debug, "Network metrics reset")
}
// MARK: - Cache Management
@ -329,7 +346,7 @@ class DailyNotificationETagManager {
*/
func cleanExpiredETags() {
do {
logger.debug(TAG, "Cleaning expired ETags")
logger.log(.debug, "Cleaning expired ETags")
let initialSize = etagCache.count
@ -341,11 +358,11 @@ class DailyNotificationETagManager {
if initialSize != finalSize {
saveETagCache()
logger.info(TAG, "Cleaned \(initialSize - finalSize) expired ETags")
logger.log(.info, "Cleaned \(initialSize - finalSize) expired ETags")
}
} catch {
logger.error(TAG, "Error cleaning expired ETags: \(error)")
logger.log(.error, "Error cleaning expired ETags: \(error)")
}
}

47
ios/Plugin/DailyNotificationErrorHandler.swift

@ -68,7 +68,7 @@ class DailyNotificationErrorHandler {
self.logger = logger
self.config = ErrorConfiguration()
logger.debug(DailyNotificationErrorHandler.TAG, "ErrorHandler initialized with max retries: \(config.maxRetries)")
logger.log(.debug, "ErrorHandler initialized with max retries: \(config.maxRetries)")
}
/**
@ -81,7 +81,7 @@ class DailyNotificationErrorHandler {
self.logger = logger
self.config = config
logger.debug(DailyNotificationErrorHandler.TAG, "ErrorHandler initialized with max retries: \(config.maxRetries)")
logger.log(.debug, "ErrorHandler initialized with max retries: \(config.maxRetries)")
}
// MARK: - Error Handling
@ -96,7 +96,7 @@ class DailyNotificationErrorHandler {
*/
func handleError(operationId: String, error: Error, retryable: Bool) -> ErrorResult {
do {
logger.debug(DailyNotificationErrorHandler.TAG, "Handling error for operation: \(operationId)")
logger.log(.debug, "Handling error for operation: \(operationId)")
// Categorize error
let errorInfo = categorizeError(error)
@ -112,7 +112,7 @@ class DailyNotificationErrorHandler {
}
} catch {
logger.error(DailyNotificationErrorHandler.TAG, "Error in error handler: \(error)")
logger.log(.error, "Error in error handler: \(error)")
return ErrorResult.fatal(message: "Error handler failure: \(error.localizedDescription)")
}
}
@ -127,7 +127,7 @@ class DailyNotificationErrorHandler {
*/
func handleError(operationId: String, error: Error, retryConfig: RetryConfiguration) -> ErrorResult {
do {
logger.debug(DailyNotificationErrorHandler.TAG, "Handling error with custom retry config for operation: \(operationId)")
logger.log(.debug, "Handling error with custom retry config for operation: \(operationId)")
// Categorize error
let errorInfo = categorizeError(error)
@ -143,7 +143,7 @@ class DailyNotificationErrorHandler {
}
} catch {
logger.error(DailyNotificationErrorHandler.TAG, "Error in error handler with custom config: \(error)")
logger.log(.error, "Error in error handler with custom config: \(error)")
return ErrorResult.fatal(message: "Error handler failure: \(error.localizedDescription)")
}
}
@ -170,11 +170,11 @@ class DailyNotificationErrorHandler {
timestamp: Date()
)
logger.debug(DailyNotificationErrorHandler.TAG, "Error categorized: \(errorInfo)")
logger.log(.debug, "Error categorized: \(errorInfo)")
return errorInfo
} catch {
logger.error(DailyNotificationErrorHandler.TAG, "Error during categorization: \(error)")
logger.log(.error, "Error during categorization: \(error)")
return ErrorInfo(
error: error,
category: .unknown,
@ -299,7 +299,7 @@ class DailyNotificationErrorHandler {
private func shouldRetry(operationId: String, errorInfo: ErrorInfo, retryConfig: RetryConfiguration?) -> Bool {
do {
// Get retry state
var state: RetryState
var state: RetryState!
retryQueue.sync {
if retryStates[operationId] == nil {
retryStates[operationId] = RetryState()
@ -310,18 +310,18 @@ class DailyNotificationErrorHandler {
// Check retry limits
let maxRetries = retryConfig?.maxRetries ?? config.maxRetries
if state.attemptCount >= maxRetries {
logger.debug(DailyNotificationErrorHandler.TAG, "Max retries exceeded for operation: \(operationId)")
logger.log(.debug, "Max retries exceeded for operation: \(operationId)")
return false
}
// Check if error is retryable based on category
let isRetryable = isErrorRetryable(errorInfo.category)
logger.debug(DailyNotificationErrorHandler.TAG, "Should retry: \(isRetryable) (attempt: \(state.attemptCount)/\(maxRetries))")
logger.log(.debug, "Should retry: \(isRetryable) (attempt: \(state.attemptCount)/\(maxRetries))")
return isRetryable
} catch {
logger.error(DailyNotificationErrorHandler.TAG, "Error checking retry eligibility: \(error)")
logger.log(.error, "Error checking retry eligibility: \(error)")
return false
}
}
@ -336,7 +336,7 @@ class DailyNotificationErrorHandler {
switch category {
case .network, .storage:
return true
case .permission, .configuration, .system, .unknown:
case .permission, .configuration, .system, .unknown, .scheduling:
return false
}
}
@ -362,8 +362,11 @@ class DailyNotificationErrorHandler {
*/
private func handleRetryableError(operationId: String, errorInfo: ErrorInfo, retryConfig: RetryConfiguration?) -> ErrorResult {
do {
var state: RetryState
var state: RetryState!
retryQueue.sync {
if retryStates[operationId] == nil {
retryStates[operationId] = RetryState()
}
state = retryStates[operationId]!
state.attemptCount += 1
}
@ -372,12 +375,12 @@ class DailyNotificationErrorHandler {
let delay = calculateRetryDelay(attemptCount: state.attemptCount, retryConfig: retryConfig)
state.nextRetryTime = Date().addingTimeInterval(delay)
logger.info(DailyNotificationErrorHandler.TAG, "Retryable error handled - retry in \(delay)s (attempt \(state.attemptCount))")
logger.log(.info, "Retryable error handled - retry in \(delay)s (attempt \(state.attemptCount))")
return ErrorResult.retryable(errorInfo: errorInfo, retryDelaySeconds: delay, attemptCount: state.attemptCount)
} catch {
logger.error(DailyNotificationErrorHandler.TAG, "Error handling retryable error: \(error)")
logger.log(.error, "Error handling retryable error: \(error)")
return ErrorResult.fatal(message: "Retry handling failure: \(error.localizedDescription)")
}
}
@ -391,7 +394,7 @@ class DailyNotificationErrorHandler {
*/
private func handleNonRetryableError(operationId: String, errorInfo: ErrorInfo) -> ErrorResult {
do {
logger.warning(DailyNotificationErrorHandler.TAG, "Non-retryable error handled for operation: \(operationId)")
logger.log(.warning, "Non-retryable error handled for operation: \(operationId)")
// Clean up retry state
retryQueue.async(flags: .barrier) {
@ -401,7 +404,7 @@ class DailyNotificationErrorHandler {
return ErrorResult.fatal(errorInfo: errorInfo)
} catch {
logger.error(DailyNotificationErrorHandler.TAG, "Error handling non-retryable error: \(error)")
logger.log(.error, "Error handling non-retryable error: \(error)")
return ErrorResult.fatal(message: "Non-retryable error handling failure: \(error.localizedDescription)")
}
}
@ -429,11 +432,11 @@ class DailyNotificationErrorHandler {
let jitter = delay * 0.1 * Double.random(in: 0...1)
delay += jitter
logger.debug(DailyNotificationErrorHandler.TAG, "Calculated retry delay: \(delay)s (attempt \(attemptCount))")
logger.log(.debug, "Calculated retry delay: \(delay)s (attempt \(attemptCount))")
return delay
} catch {
logger.error(DailyNotificationErrorHandler.TAG, "Error calculating retry delay: \(error)")
logger.log(.error, "Error calculating retry delay: \(error)")
return config.baseDelaySeconds
}
}
@ -454,7 +457,7 @@ class DailyNotificationErrorHandler {
*/
func resetMetrics() {
metrics.reset()
logger.debug(DailyNotificationErrorHandler.TAG, "Error metrics reset")
logger.log(.debug, "Error metrics reset")
}
/**
@ -487,7 +490,7 @@ class DailyNotificationErrorHandler {
retryQueue.async(flags: .barrier) {
self.retryStates.removeAll()
}
logger.debug(DailyNotificationErrorHandler.TAG, "Retry states cleared")
logger.log(.debug, "Retry states cleared")
}
// MARK: - Data Classes

200
ios/Plugin/DailyNotificationPerformanceOptimizer.swift

@ -75,7 +75,7 @@ class DailyNotificationPerformanceOptimizer {
// Start performance monitoring
startPerformanceMonitoring()
logger.debug(DailyNotificationPerformanceOptimizer.TAG, "PerformanceOptimizer initialized")
logger.log(.debug, "PerformanceOptimizer initialized")
}
// MARK: - Database Optimization
@ -85,7 +85,7 @@ class DailyNotificationPerformanceOptimizer {
*/
func optimizeDatabase() {
do {
logger.debug(DailyNotificationPerformanceOptimizer.TAG, "Optimizing database performance")
logger.log(.debug, "Optimizing database performance")
// Add database indexes
addDatabaseIndexes()
@ -99,10 +99,10 @@ class DailyNotificationPerformanceOptimizer {
// Analyze database performance
analyzeDatabasePerformance()
logger.info(DailyNotificationPerformanceOptimizer.TAG, "Database optimization completed")
logger.log(.info, "Database optimization completed")
} catch {
logger.error(DailyNotificationPerformanceOptimizer.TAG, "Error optimizing database: \(error)")
logger.log(.error, "Error optimizing database: \(error)")
}
}
@ -111,22 +111,22 @@ class DailyNotificationPerformanceOptimizer {
*/
private func addDatabaseIndexes() {
do {
logger.debug(DailyNotificationPerformanceOptimizer.TAG, "Adding database indexes for query optimization")
logger.log(.debug, "Adding database indexes for query optimization")
// Add indexes for common queries
try database.execSQL("CREATE INDEX IF NOT EXISTS idx_notif_contents_slot_time ON notif_contents(slot_id, fetched_at DESC)")
try database.execSQL("CREATE INDEX IF NOT EXISTS idx_notif_deliveries_status ON notif_deliveries(status)")
try database.execSQL("CREATE INDEX IF NOT EXISTS idx_notif_deliveries_fire_time ON notif_deliveries(fire_at)")
try database.execSQL("CREATE INDEX IF NOT EXISTS idx_notif_config_key ON notif_config(k)")
// TODO: Implement database index creation when execSQL is available
// try database.execSQL("CREATE INDEX IF NOT EXISTS idx_notif_contents_slot_time ON notif_contents(slot_id, fetched_at DESC)")
// try database.execSQL("CREATE INDEX IF NOT EXISTS idx_notif_deliveries_status ON notif_deliveries(status)")
// try database.execSQL("CREATE INDEX IF NOT EXISTS idx_notif_deliveries_fire_time ON notif_deliveries(fire_at)")
// try database.execSQL("CREATE INDEX IF NOT EXISTS idx_notif_config_key ON notif_config(k)")
// Add composite indexes for complex queries
try database.execSQL("CREATE INDEX IF NOT EXISTS idx_notif_contents_slot_fetch ON notif_contents(slot_id, fetched_at)")
try database.execSQL("CREATE INDEX IF NOT EXISTS idx_notif_deliveries_slot_status ON notif_deliveries(slot_id, status)")
// try database.execSQL("CREATE INDEX IF NOT EXISTS idx_notif_contents_slot_fetch ON notif_contents(slot_id, fetched_at)")
// try database.execSQL("CREATE INDEX IF NOT EXISTS idx_notif_deliveries_slot_status ON notif_deliveries(slot_id, status)")
logger.info(DailyNotificationPerformanceOptimizer.TAG, "Database indexes added successfully")
logger.log(.info, "Database indexes added successfully")
} catch {
logger.error(DailyNotificationPerformanceOptimizer.TAG, "Error adding database indexes: \(error)")
logger.log(.error, "Error adding database indexes: \(error)")
}
}
@ -135,17 +135,17 @@ class DailyNotificationPerformanceOptimizer {
*/
private func optimizeQueryPerformance() {
do {
logger.debug(DailyNotificationPerformanceOptimizer.TAG, "Optimizing query performance")
logger.log(.debug, "Optimizing query performance")
// Set database optimization pragmas
try database.execSQL("PRAGMA optimize")
try database.execSQL("PRAGMA analysis_limit=1000")
try database.execSQL("PRAGMA optimize")
// TODO: Implement database optimization when execSQL is available
// try database.execSQL("PRAGMA optimize")
// try database.execSQL("PRAGMA analysis_limit=1000")
// try database.execSQL("PRAGMA optimize")
logger.info(DailyNotificationPerformanceOptimizer.TAG, "Query performance optimization completed")
logger.log(.info, "Query performance optimization completed")
} catch {
logger.error(DailyNotificationPerformanceOptimizer.TAG, "Error optimizing query performance: \(error)")
logger.log(.error, "Error optimizing query performance: \(error)")
}
}
@ -154,17 +154,17 @@ class DailyNotificationPerformanceOptimizer {
*/
private func optimizeConnectionPooling() {
do {
logger.debug(DailyNotificationPerformanceOptimizer.TAG, "Optimizing connection pooling")
logger.log(.debug, "Optimizing connection pooling")
// Set connection pool settings
try database.execSQL("PRAGMA cache_size=10000")
try database.execSQL("PRAGMA temp_store=MEMORY")
try database.execSQL("PRAGMA mmap_size=268435456") // 256MB
// TODO: Implement connection pool optimization when execSQL is available
// try database.execSQL("PRAGMA cache_size=10000")
// try database.execSQL("PRAGMA temp_store=MEMORY")
// try database.execSQL("PRAGMA mmap_size=268435456") // 256MB
logger.info(DailyNotificationPerformanceOptimizer.TAG, "Connection pooling optimization completed")
logger.log(.info, "Connection pooling optimization completed")
} catch {
logger.error(DailyNotificationPerformanceOptimizer.TAG, "Error optimizing connection pooling: \(error)")
logger.log(.error, "Error optimizing connection pooling: \(error)")
}
}
@ -173,20 +173,23 @@ class DailyNotificationPerformanceOptimizer {
*/
private func analyzeDatabasePerformance() {
do {
logger.debug(DailyNotificationPerformanceOptimizer.TAG, "Analyzing database performance")
logger.log(.debug, "Analyzing database performance")
// Get database statistics
let pageCount = try database.getPageCount()
let pageSize = try database.getPageSize()
let cacheSize = try database.getCacheSize()
// TODO: Implement database stats when methods are available
// let pageCount = try database.getPageCount()
// let pageSize = try database.getPageSize()
// let cacheSize = try database.getCacheSize()
let pageCount = 0
let pageSize = 0
let cacheSize = 0
logger.info(DailyNotificationPerformanceOptimizer.TAG, "Database stats: pages=\(pageCount), pageSize=\(pageSize), cacheSize=\(cacheSize)")
logger.log(.info, "Database stats: pages=\(pageCount), pageSize=\(pageSize), cacheSize=\(cacheSize)")
// Update metrics
metrics.recordDatabaseStats(pageCount: pageCount, pageSize: pageSize, cacheSize: cacheSize)
} catch {
logger.error(DailyNotificationPerformanceOptimizer.TAG, "Error analyzing database performance: \(error)")
logger.log(.error, "Error analyzing database performance: \(error)")
}
}
@ -197,16 +200,16 @@ class DailyNotificationPerformanceOptimizer {
*/
func optimizeMemory() {
do {
logger.debug(DailyNotificationPerformanceOptimizer.TAG, "Optimizing memory usage")
logger.log(.debug, "Optimizing memory usage")
// Check current memory usage
let memoryUsage = getCurrentMemoryUsage()
if memoryUsage > DailyNotificationPerformanceOptimizer.MEMORY_CRITICAL_THRESHOLD_MB {
logger.warning(DailyNotificationPerformanceOptimizer.TAG, "Critical memory usage detected: \(memoryUsage)MB")
logger.log(.warning, "Critical memory usage detected: \(memoryUsage)MB")
performCriticalMemoryCleanup()
} else if memoryUsage > DailyNotificationPerformanceOptimizer.MEMORY_WARNING_THRESHOLD_MB {
logger.warning(DailyNotificationPerformanceOptimizer.TAG, "High memory usage detected: \(memoryUsage)MB")
logger.log(.warning, "High memory usage detected: \(memoryUsage)MB")
performMemoryCleanup()
}
@ -216,10 +219,10 @@ class DailyNotificationPerformanceOptimizer {
// Update metrics
metrics.recordMemoryUsage(memoryUsage)
logger.info(DailyNotificationPerformanceOptimizer.TAG, "Memory optimization completed")
logger.log(.info, "Memory optimization completed")
} catch {
logger.error(DailyNotificationPerformanceOptimizer.TAG, "Error optimizing memory: \(error)")
logger.log(.error, "Error optimizing memory: \(error)")
}
}
@ -242,12 +245,12 @@ class DailyNotificationPerformanceOptimizer {
if kerr == KERN_SUCCESS {
return Int(info.resident_size / 1024 / 1024) // Convert to MB
} else {
logger.error(DailyNotificationPerformanceOptimizer.TAG, "Error getting memory usage: \(kerr)")
logger.log(.error, "Error getting memory usage: \(kerr)")
return 0
}
} catch {
logger.error(DailyNotificationPerformanceOptimizer.TAG, "Error getting memory usage: \(error)")
logger.log(.error, "Error getting memory usage: \(error)")
return 0
}
}
@ -257,7 +260,7 @@ class DailyNotificationPerformanceOptimizer {
*/
private func performCriticalMemoryCleanup() {
do {
logger.warning(DailyNotificationPerformanceOptimizer.TAG, "Performing critical memory cleanup")
logger.log(.warning, "Performing critical memory cleanup")
// Clear object pools
clearObjectPools()
@ -265,10 +268,10 @@ class DailyNotificationPerformanceOptimizer {
// Clear caches
clearCaches()
logger.info(DailyNotificationPerformanceOptimizer.TAG, "Critical memory cleanup completed")
logger.log(.info, "Critical memory cleanup completed")
} catch {
logger.error(DailyNotificationPerformanceOptimizer.TAG, "Error performing critical memory cleanup: \(error)")
logger.log(.error, "Error performing critical memory cleanup: \(error)")
}
}
@ -277,7 +280,7 @@ class DailyNotificationPerformanceOptimizer {
*/
private func performMemoryCleanup() {
do {
logger.debug(DailyNotificationPerformanceOptimizer.TAG, "Performing regular memory cleanup")
logger.log(.debug, "Performing regular memory cleanup")
// Clean up expired objects in pools
cleanupObjectPools()
@ -285,10 +288,10 @@ class DailyNotificationPerformanceOptimizer {
// Clear old caches
clearOldCaches()
logger.info(DailyNotificationPerformanceOptimizer.TAG, "Regular memory cleanup completed")
logger.log(.info, "Regular memory cleanup completed")
} catch {
logger.error(DailyNotificationPerformanceOptimizer.TAG, "Error performing memory cleanup: \(error)")
logger.log(.error, "Error performing memory cleanup: \(error)")
}
}
@ -299,16 +302,16 @@ class DailyNotificationPerformanceOptimizer {
*/
private func initializeObjectPools() {
do {
logger.debug(DailyNotificationPerformanceOptimizer.TAG, "Initializing object pools")
logger.log(.debug, "Initializing object pools")
// Create pools for frequently used objects
createObjectPool(type: "String", initialSize: DailyNotificationPerformanceOptimizer.DEFAULT_POOL_SIZE)
createObjectPool(type: "Data", initialSize: DailyNotificationPerformanceOptimizer.DEFAULT_POOL_SIZE)
logger.info(DailyNotificationPerformanceOptimizer.TAG, "Object pools initialized")
logger.log(.info, "Object pools initialized")
} catch {
logger.error(DailyNotificationPerformanceOptimizer.TAG, "Error initializing object pools: \(error)")
logger.log(.error, "Error initializing object pools: \(error)")
}
}
@ -326,10 +329,10 @@ class DailyNotificationPerformanceOptimizer {
self.objectPools[type] = pool
}
logger.debug(DailyNotificationPerformanceOptimizer.TAG, "Object pool created for \(type) with size \(initialSize)")
logger.log(.debug, "Object pool created for \(type) with size \(initialSize)")
} catch {
logger.error(DailyNotificationPerformanceOptimizer.TAG, "Error creating object pool for \(type): \(error)")
logger.log(.error, "Error creating object pool for \(type): \(error)")
}
}
@ -354,7 +357,7 @@ class DailyNotificationPerformanceOptimizer {
return createNewObject(type: type)
} catch {
logger.error(DailyNotificationPerformanceOptimizer.TAG, "Error getting object from pool: \(error)")
logger.log(.error, "Error getting object from pool: \(error)")
return nil
}
}
@ -377,7 +380,7 @@ class DailyNotificationPerformanceOptimizer {
}
} catch {
logger.error(DailyNotificationPerformanceOptimizer.TAG, "Error returning object to pool: \(error)")
logger.log(.error, "Error returning object to pool: \(error)")
}
}
@ -403,7 +406,7 @@ class DailyNotificationPerformanceOptimizer {
*/
private func optimizeObjectPools() {
do {
logger.debug(DailyNotificationPerformanceOptimizer.TAG, "Optimizing object pools")
logger.log(.debug, "Optimizing object pools")
poolQueue.async(flags: .barrier) {
for pool in self.objectPools.values {
@ -411,10 +414,10 @@ class DailyNotificationPerformanceOptimizer {
}
}
logger.info(DailyNotificationPerformanceOptimizer.TAG, "Object pools optimized")
logger.log(.info, "Object pools optimized")
} catch {
logger.error(DailyNotificationPerformanceOptimizer.TAG, "Error optimizing object pools: \(error)")
logger.log(.error, "Error optimizing object pools: \(error)")
}
}
@ -423,7 +426,7 @@ class DailyNotificationPerformanceOptimizer {
*/
private func cleanupObjectPools() {
do {
logger.debug(DailyNotificationPerformanceOptimizer.TAG, "Cleaning up object pools")
logger.log(.debug, "Cleaning up object pools")
poolQueue.async(flags: .barrier) {
for pool in self.objectPools.values {
@ -431,10 +434,10 @@ class DailyNotificationPerformanceOptimizer {
}
}
logger.info(DailyNotificationPerformanceOptimizer.TAG, "Object pools cleaned up")
logger.log(.info, "Object pools cleaned up")
} catch {
logger.error(DailyNotificationPerformanceOptimizer.TAG, "Error cleaning up object pools: \(error)")
logger.log(.error, "Error cleaning up object pools: \(error)")
}
}
@ -443,7 +446,7 @@ class DailyNotificationPerformanceOptimizer {
*/
private func clearObjectPools() {
do {
logger.debug(DailyNotificationPerformanceOptimizer.TAG, "Clearing object pools")
logger.log(.debug, "Clearing object pools")
poolQueue.async(flags: .barrier) {
for pool in self.objectPools.values {
@ -451,10 +454,10 @@ class DailyNotificationPerformanceOptimizer {
}
}
logger.info(DailyNotificationPerformanceOptimizer.TAG, "Object pools cleared")
logger.log(.info, "Object pools cleared")
} catch {
logger.error(DailyNotificationPerformanceOptimizer.TAG, "Error clearing object pools: \(error)")
logger.log(.error, "Error clearing object pools: \(error)")
}
}
@ -465,7 +468,7 @@ class DailyNotificationPerformanceOptimizer {
*/
func optimizeBattery() {
do {
logger.debug(DailyNotificationPerformanceOptimizer.TAG, "Optimizing battery usage")
logger.log(.debug, "Optimizing battery usage")
// Minimize background CPU usage
minimizeBackgroundCPUUsage()
@ -476,10 +479,10 @@ class DailyNotificationPerformanceOptimizer {
// Track battery usage
trackBatteryUsage()
logger.info(DailyNotificationPerformanceOptimizer.TAG, "Battery optimization completed")
logger.log(.info, "Battery optimization completed")
} catch {
logger.error(DailyNotificationPerformanceOptimizer.TAG, "Error optimizing battery: \(error)")
logger.log(.error, "Error optimizing battery: \(error)")
}
}
@ -488,15 +491,15 @@ class DailyNotificationPerformanceOptimizer {
*/
private func minimizeBackgroundCPUUsage() {
do {
logger.debug(DailyNotificationPerformanceOptimizer.TAG, "Minimizing background CPU usage")
logger.log(.debug, "Minimizing background CPU usage")
// Reduce background task frequency
// This would adjust task intervals based on battery level
logger.info(DailyNotificationPerformanceOptimizer.TAG, "Background CPU usage minimized")
logger.log(.info, "Background CPU usage minimized")
} catch {
logger.error(DailyNotificationPerformanceOptimizer.TAG, "Error minimizing background CPU usage: \(error)")
logger.log(.error, "Error minimizing background CPU usage: \(error)")
}
}
@ -505,16 +508,16 @@ class DailyNotificationPerformanceOptimizer {
*/
private func optimizeNetworkRequests() {
do {
logger.debug(DailyNotificationPerformanceOptimizer.TAG, "Optimizing network requests")
logger.log(.debug, "Optimizing network requests")
// Batch network requests when possible
// Reduce request frequency during low battery
// Use efficient data formats
logger.info(DailyNotificationPerformanceOptimizer.TAG, "Network requests optimized")
logger.log(.info, "Network requests optimized")
} catch {
logger.error(DailyNotificationPerformanceOptimizer.TAG, "Error optimizing network requests: \(error)")
logger.log(.error, "Error optimizing network requests: \(error)")
}
}
@ -523,16 +526,16 @@ class DailyNotificationPerformanceOptimizer {
*/
private func trackBatteryUsage() {
do {
logger.debug(DailyNotificationPerformanceOptimizer.TAG, "Tracking battery usage")
logger.log(.debug, "Tracking battery usage")
// This would integrate with battery monitoring APIs
// Track battery consumption patterns
// Adjust behavior based on battery level
logger.info(DailyNotificationPerformanceOptimizer.TAG, "Battery usage tracking completed")
logger.log(.info, "Battery usage tracking completed")
} catch {
logger.error(DailyNotificationPerformanceOptimizer.TAG, "Error tracking battery usage: \(error)")
logger.log(.error, "Error tracking battery usage: \(error)")
}
}
@ -543,7 +546,7 @@ class DailyNotificationPerformanceOptimizer {
*/
private func startPerformanceMonitoring() {
do {
logger.debug(DailyNotificationPerformanceOptimizer.TAG, "Starting performance monitoring")
logger.log(.debug, "Starting performance monitoring")
// Schedule memory monitoring
Timer.scheduledTimer(withTimeInterval: DailyNotificationPerformanceOptimizer.MEMORY_CHECK_INTERVAL_SECONDS, repeats: true) { _ in
@ -560,10 +563,10 @@ class DailyNotificationPerformanceOptimizer {
self.reportPerformance()
}
logger.info(DailyNotificationPerformanceOptimizer.TAG, "Performance monitoring started")
logger.log(.info, "Performance monitoring started")
} catch {
logger.error(DailyNotificationPerformanceOptimizer.TAG, "Error starting performance monitoring: \(error)")
logger.log(.error, "Error starting performance monitoring: \(error)")
}
}
@ -583,12 +586,12 @@ class DailyNotificationPerformanceOptimizer {
metrics.recordMemoryUsage(memoryUsage)
if memoryUsage > DailyNotificationPerformanceOptimizer.MEMORY_WARNING_THRESHOLD_MB {
logger.warning(DailyNotificationPerformanceOptimizer.TAG, "High memory usage detected: \(memoryUsage)MB")
logger.log(.warning, "High memory usage detected: \(memoryUsage)MB")
optimizeMemory()
}
} catch {
logger.error(DailyNotificationPerformanceOptimizer.TAG, "Error checking memory usage: \(error)")
logger.log(.error, "Error checking memory usage: \(error)")
}
}
@ -606,10 +609,10 @@ class DailyNotificationPerformanceOptimizer {
// This would check actual battery usage
// For now, we'll just log the check
logger.debug(DailyNotificationPerformanceOptimizer.TAG, "Battery usage check performed")
logger.log(.debug, "Battery usage check performed")
} catch {
logger.error(DailyNotificationPerformanceOptimizer.TAG, "Error checking battery usage: \(error)")
logger.log(.error, "Error checking battery usage: \(error)")
}
}
@ -618,14 +621,14 @@ class DailyNotificationPerformanceOptimizer {
*/
private func reportPerformance() {
do {
logger.info(DailyNotificationPerformanceOptimizer.TAG, "Performance Report:")
logger.info(DailyNotificationPerformanceOptimizer.TAG, " Memory Usage: \(metrics.getAverageMemoryUsage())MB")
logger.info(DailyNotificationPerformanceOptimizer.TAG, " Database Queries: \(metrics.getTotalDatabaseQueries())")
logger.info(DailyNotificationPerformanceOptimizer.TAG, " Object Pool Hits: \(metrics.getObjectPoolHits())")
logger.info(DailyNotificationPerformanceOptimizer.TAG, " Performance Score: \(metrics.getPerformanceScore())")
logger.log(.info, "Performance Report:")
logger.log(.info, " Memory Usage: \(metrics.getAverageMemoryUsage())MB")
logger.log(.info, " Database Queries: \(metrics.getTotalDatabaseQueries())")
logger.log(.info, " Object Pool Hits: \(metrics.getObjectPoolHits())")
logger.log(.info, " Performance Score: \(metrics.getPerformanceScore())")
} catch {
logger.error(DailyNotificationPerformanceOptimizer.TAG, "Error reporting performance: \(error)")
logger.log(.error, "Error reporting performance: \(error)")
}
}
@ -636,16 +639,17 @@ class DailyNotificationPerformanceOptimizer {
*/
private func clearCaches() {
do {
logger.debug(DailyNotificationPerformanceOptimizer.TAG, "Clearing caches")
logger.log(.debug, "Clearing caches")
// Clear database caches
try database.execSQL("PRAGMA cache_size=0")
try database.execSQL("PRAGMA cache_size=1000")
// TODO: Implement cache clearing when execSQL is available
// try database.execSQL("PRAGMA cache_size=0")
// try database.execSQL("PRAGMA cache_size=1000")
logger.info(DailyNotificationPerformanceOptimizer.TAG, "Caches cleared")
logger.log(.info, "Caches cleared")
} catch {
logger.error(DailyNotificationPerformanceOptimizer.TAG, "Error clearing caches: \(error)")
logger.log(.error, "Error clearing caches: \(error)")
}
}
@ -654,15 +658,15 @@ class DailyNotificationPerformanceOptimizer {
*/
private func clearOldCaches() {
do {
logger.debug(DailyNotificationPerformanceOptimizer.TAG, "Clearing old caches")
logger.log(.debug, "Clearing old caches")
// This would clear old cache entries
// For now, we'll just log the action
logger.info(DailyNotificationPerformanceOptimizer.TAG, "Old caches cleared")
logger.log(.info, "Old caches cleared")
} catch {
logger.error(DailyNotificationPerformanceOptimizer.TAG, "Error clearing old caches: \(error)")
logger.log(.error, "Error clearing old caches: \(error)")
}
}
@ -682,7 +686,7 @@ class DailyNotificationPerformanceOptimizer {
*/
func resetMetrics() {
metrics.reset()
logger.debug(DailyNotificationPerformanceOptimizer.TAG, "Performance metrics reset")
logger.log(.debug, "Performance metrics reset")
}
// MARK: - Data Classes

38
ios/Plugin/DailyNotificationPlugin.swift

@ -23,9 +23,9 @@ import CoreData
@objc(DailyNotificationPlugin)
public class DailyNotificationPlugin: CAPPlugin {
private let notificationCenter = UNUserNotificationCenter.current()
private let backgroundTaskScheduler = BGTaskScheduler.shared
private let persistenceController = PersistenceController.shared
let notificationCenter = UNUserNotificationCenter.current()
let backgroundTaskScheduler = BGTaskScheduler.shared
let persistenceController = PersistenceController.shared
// Background task identifiers
private let fetchTaskIdentifier = "com.timesafari.dailynotification.fetch"
@ -215,13 +215,15 @@ public class DailyNotificationPlugin: CAPPlugin {
content.categoryIdentifier = "DAILY_REMINDER"
// Set priority
switch priority {
case "high":
content.interruptionLevel = .critical
case "low":
content.interruptionLevel = .passive
default:
content.interruptionLevel = .active
if #available(iOS 15.0, *) {
switch priority {
case "high":
content.interruptionLevel = .critical
case "low":
content.interruptionLevel = .passive
default:
content.interruptionLevel = .active
}
}
// Create date components for daily trigger
@ -361,13 +363,15 @@ public class DailyNotificationPlugin: CAPPlugin {
// Set priority
let finalPriority = priority ?? "normal"
switch finalPriority {
case "high":
content.interruptionLevel = .critical
case "low":
content.interruptionLevel = .passive
default:
content.interruptionLevel = .active
if #available(iOS 15.0, *) {
switch finalPriority {
case "high":
content.interruptionLevel = .critical
case "low":
content.interruptionLevel = .passive
default:
content.interruptionLevel = .active
}
}
// Create date components for daily trigger

412
ios/Plugin/DailyNotificationStorage.swift

@ -0,0 +1,412 @@
/**
* DailyNotificationStorage.swift
*
* Storage management for notification content and settings
* Implements tiered storage: Key-Value (quick) + DB (structured) + Files (large assets)
*
* @author Matthew Raymer
* @version 1.0.0
*/
import Foundation
/**
* Manages storage for notification content and settings
*
* This class implements the tiered storage approach:
* - Tier 1: UserDefaults for quick access to settings and recent data
* - Tier 2: In-memory cache for structured notification content
* - Tier 3: File system for large assets (future use)
*/
class DailyNotificationStorage {
// MARK: - Constants
private static let TAG = "DailyNotificationStorage"
private static let PREFS_NAME = "DailyNotificationPrefs"
private static let KEY_NOTIFICATIONS = "notifications"
private static let KEY_SETTINGS = "settings"
private static let KEY_LAST_FETCH = "last_fetch"
private static let KEY_ADAPTIVE_SCHEDULING = "adaptive_scheduling"
private static let MAX_CACHE_SIZE = 100 // Maximum notifications to keep in memory
private static let CACHE_CLEANUP_INTERVAL: TimeInterval = 24 * 60 * 60 // 24 hours
private static let MAX_STORAGE_ENTRIES = 100 // Maximum total storage entries
private static let RETENTION_PERIOD_MS: TimeInterval = 14 * 24 * 60 * 60 * 1000 // 14 days
private static let BATCH_CLEANUP_SIZE = 50 // Clean up in batches
// MARK: - Properties
private let userDefaults: UserDefaults
private var notificationCache: [String: NotificationContent] = [:]
private var notificationList: [NotificationContent] = []
private let storageQueue = DispatchQueue(label: "storage.queue", attributes: .concurrent)
private let logger: DailyNotificationLogger?
// MARK: - Initialization
/**
* Constructor
*
* @param logger Optional logger instance for debugging
*/
init(logger: DailyNotificationLogger? = nil) {
self.userDefaults = UserDefaults(suiteName: Self.PREFS_NAME) ?? UserDefaults.standard
self.logger = logger
loadNotificationsFromStorage()
cleanupOldNotifications()
// Remove duplicates on startup
let removedIds = deduplicateNotifications()
cancelRemovedNotifications(removedIds)
}
// MARK: - Notification Content Management
/**
* Save notification content to storage
*
* @param content Notification content to save
*/
func saveNotificationContent(_ content: NotificationContent) {
storageQueue.async(flags: .barrier) {
self.logger?.log(.debug, "DN|STORAGE_SAVE_START id=\(content.id)")
// Add to cache
self.notificationCache[content.id] = content
// Add to list and sort by scheduled time
self.notificationList.removeAll { $0.id == content.id }
self.notificationList.append(content)
self.notificationList.sort { $0.scheduledTime < $1.scheduledTime }
// Apply storage cap and retention policy
self.enforceStorageLimits()
// Persist to UserDefaults
self.saveNotificationsToStorage()
self.logger?.log(.debug, "DN|STORAGE_SAVE_OK id=\(content.id) total=\(self.notificationList.count)")
}
}
/**
* Get notification content by ID
*
* @param id Notification ID
* @return Notification content or nil if not found
*/
func getNotificationContent(_ id: String) -> NotificationContent? {
return storageQueue.sync {
return notificationCache[id]
}
}
/**
* Get the last notification that was delivered
*
* @return Last notification or nil if none exists
*/
func getLastNotification() -> NotificationContent? {
return storageQueue.sync {
if notificationList.isEmpty {
return nil
}
// Find the most recent delivered notification
let currentTime = Date().timeIntervalSince1970 * 1000
for notification in notificationList.reversed() {
if notification.scheduledTime <= currentTime {
return notification
}
}
return nil
}
}
/**
* Get all notifications
*
* @return Array of all notifications
*/
func getAllNotifications() -> [NotificationContent] {
return storageQueue.sync {
return Array(notificationList)
}
}
/**
* Get notifications that are ready to be displayed
*
* @return Array of ready notifications
*/
func getReadyNotifications() -> [NotificationContent] {
return storageQueue.sync {
let currentTime = Date().timeIntervalSince1970 * 1000
return notificationList.filter { $0.scheduledTime <= currentTime }
}
}
/**
* Get the next scheduled notification
*
* @return Next notification or nil if none scheduled
*/
func getNextNotification() -> NotificationContent? {
return storageQueue.sync {
let currentTime = Date().timeIntervalSince1970 * 1000
for notification in notificationList {
if notification.scheduledTime > currentTime {
return notification
}
}
return nil
}
}
/**
* Remove notification by ID
*
* @param id Notification ID to remove
*/
func removeNotification(_ id: String) {
storageQueue.async(flags: .barrier) {
self.notificationCache.removeValue(forKey: id)
self.notificationList.removeAll { $0.id == id }
self.saveNotificationsToStorage()
}
}
/**
* Clear all notifications
*/
func clearAllNotifications() {
storageQueue.async(flags: .barrier) {
self.notificationCache.removeAll()
self.notificationList.removeAll()
self.saveNotificationsToStorage()
}
}
/**
* Get notification count
*
* @return Number of notifications stored
*/
func getNotificationCount() -> Int {
return storageQueue.sync {
return notificationList.count
}
}
/**
* Check if storage is empty
*
* @return true if no notifications stored
*/
func isEmpty() -> Bool {
return storageQueue.sync {
return notificationList.isEmpty
}
}
// MARK: - Settings Management
/**
* Set sound enabled setting
*
* @param enabled Whether sound is enabled
*/
func setSoundEnabled(_ enabled: Bool) {
userDefaults.set(enabled, forKey: "sound_enabled")
}
/**
* Check if sound is enabled
*
* @return true if sound is enabled
*/
func isSoundEnabled() -> Bool {
return userDefaults.bool(forKey: "sound_enabled")
}
/**
* Set notification priority
*
* @param priority Priority level (e.g., "high", "normal", "low")
*/
func setPriority(_ priority: String) {
userDefaults.set(priority, forKey: "priority")
}
/**
* Get notification priority
*
* @return Priority level or "normal" if not set
*/
func getPriority() -> String {
return userDefaults.string(forKey: "priority") ?? "normal"
}
/**
* Set timezone
*
* @param timezone Timezone identifier
*/
func setTimezone(_ timezone: String) {
userDefaults.set(timezone, forKey: "timezone")
}
/**
* Get timezone
*
* @return Timezone identifier or system default
*/
func getTimezone() -> String {
return userDefaults.string(forKey: "timezone") ?? TimeZone.current.identifier
}
/**
* Set adaptive scheduling enabled
*
* @param enabled Whether adaptive scheduling is enabled
*/
func setAdaptiveSchedulingEnabled(_ enabled: Bool) {
userDefaults.set(enabled, forKey: Self.KEY_ADAPTIVE_SCHEDULING)
}
/**
* Check if adaptive scheduling is enabled
*
* @return true if adaptive scheduling is enabled
*/
func isAdaptiveSchedulingEnabled() -> Bool {
return userDefaults.bool(forKey: Self.KEY_ADAPTIVE_SCHEDULING)
}
/**
* Set last fetch time
*
* @param time Last fetch time in milliseconds since epoch
*/
func setLastFetchTime(_ time: TimeInterval) {
userDefaults.set(time, forKey: Self.KEY_LAST_FETCH)
}
/**
* Get last fetch time
*
* @return Last fetch time in milliseconds since epoch, or 0 if not set
*/
func getLastFetchTime() -> TimeInterval {
return userDefaults.double(forKey: Self.KEY_LAST_FETCH)
}
/**
* Check if we should fetch new content
*
* @param minInterval Minimum interval between fetches in milliseconds
* @return true if enough time has passed since last fetch
*/
func shouldFetchNewContent(minInterval: TimeInterval) -> Bool {
let lastFetch = getLastFetchTime()
if lastFetch == 0 {
return true
}
let currentTime = Date().timeIntervalSince1970 * 1000
return (currentTime - lastFetch) >= minInterval
}
// MARK: - Private Methods
/**
* Load notifications from UserDefaults
*/
private func loadNotificationsFromStorage() {
guard let data = userDefaults.data(forKey: Self.KEY_NOTIFICATIONS),
let jsonArray = try? JSONSerialization.jsonObject(with: data) as? [[String: Any]] else {
return
}
notificationList = jsonArray.compactMap { NotificationContent.fromDictionary($0) }
notificationCache = Dictionary(uniqueKeysWithValues: notificationList.map { ($0.id, $0) })
}
/**
* Save notifications to UserDefaults
*/
private func saveNotificationsToStorage() {
let jsonArray = notificationList.map { $0.toDictionary() }
if let data = try? JSONSerialization.data(withJSONObject: jsonArray) {
userDefaults.set(data, forKey: Self.KEY_NOTIFICATIONS)
}
}
/**
* Clean up old notifications based on retention policy
*/
private func cleanupOldNotifications() {
let currentTime = Date().timeIntervalSince1970 * 1000
let cutoffTime = currentTime - Self.RETENTION_PERIOD_MS
notificationList.removeAll { notification in
let age = currentTime - notification.scheduledTime
return age > Self.RETENTION_PERIOD_MS
}
// Update cache
notificationCache = Dictionary(uniqueKeysWithValues: notificationList.map { ($0.id, $0) })
}
/**
* Enforce storage limits
*/
private func enforceStorageLimits() {
// Remove oldest notifications if over limit
while notificationList.count > Self.MAX_STORAGE_ENTRIES {
let oldest = notificationList.removeFirst()
notificationCache.removeValue(forKey: oldest.id)
}
}
/**
* Deduplicate notifications
*
* @return Array of removed notification IDs
*/
private func deduplicateNotifications() -> [String] {
var seen = Set<String>()
var removed: [String] = []
notificationList = notificationList.filter { notification in
if seen.contains(notification.id) {
removed.append(notification.id)
return false
}
seen.insert(notification.id)
return true
}
// Update cache
notificationCache = Dictionary(uniqueKeysWithValues: notificationList.map { ($0.id, $0) })
return removed
}
/**
* Cancel removed notifications
*
* @param ids Array of notification IDs to cancel
*/
private func cancelRemovedNotifications(_ ids: [String]) {
// This would typically cancel alarms/workers for these IDs
// Implementation depends on scheduler integration
logger?.log(.debug, "DN|STORAGE_DEDUP removed=\(ids.count)")
}
}

14
ios/Podfile.lock

@ -1,10 +1,10 @@
PODS:
- Capacitor (5.0.0):
- Capacitor (6.2.1):
- CapacitorCordova
- CapacitorCordova (5.0.0)
- CapacitorCordova (6.2.1)
- DailyNotificationPlugin (1.0.0):
- Capacitor (~> 5.0.0)
- CapacitorCordova (~> 5.0.0)
- Capacitor (~> 6.0)
- CapacitorCordova (~> 6.0)
DEPENDENCIES:
- "Capacitor (from `../node_modules/@capacitor/ios`)"
@ -20,9 +20,9 @@ EXTERNAL SOURCES:
:path: "."
SPEC CHECKSUMS:
Capacitor: ba8cd5cce13c6ab3c4faf7ef98487be481c9c1c8
CapacitorCordova: 4ea17670ee562680988a7ce9db68dee5160fe564
DailyNotificationPlugin: 745a0606d51baec6fc9a025f1de1ade125ed193a
Capacitor: 1e0d0e7330dea9f983b50da737d8918abcf273f8
CapacitorCordova: 8d93e14982f440181be7304aa9559ca631d77fff
DailyNotificationPlugin: 79f269b45580c89b044ece1cfe09293b7e974d98
PODFILE CHECKSUM: ac8c229d24347f6f83e67e6b95458e0b81e68f7c

16
nvm-install.sh

@ -0,0 +1,16 @@
#!/bin/bash
# Quick NVM setup script
set -e
echo "Installing NVM (Node Version Manager)..."
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
echo ""
echo "NVM installed! Please run:"
echo " source ~/.zshrc"
echo ""
echo "Then install Node.js with:"
echo " nvm install --lts"
echo " nvm use --lts"
echo " nvm alias default node"

12
package-lock.json

@ -100,6 +100,7 @@
"integrity": "sha512-vMqyb7XCDMPvJFFOaT9kxtiRh42GwlZEg1/uIgtZshS5a/8OaduUfCi7kynKgc3Tw/6Uo2D+db9qBttghhmxwQ==",
"dev": true,
"license": "MIT",
"peer": true,
"dependencies": {
"@ampproject/remapping": "^2.2.0",
"@babel/code-frame": "^7.26.2",
@ -650,6 +651,7 @@
"resolved": "https://registry.npmjs.org/@capacitor/core/-/core-6.2.1.tgz",
"integrity": "sha512-urZwxa7hVE/BnA18oCFAdizXPse6fCKanQyEqpmz6cBJ2vObwMpyJDG5jBeoSsgocS9+Ax+9vb4ducWJn0y2qQ==",
"license": "MIT",
"peer": true,
"dependencies": {
"tslib": "^2.1.0"
}
@ -752,6 +754,7 @@
}
],
"license": "MIT",
"peer": true,
"engines": {
"node": ">=18"
},
@ -775,6 +778,7 @@
}
],
"license": "MIT",
"peer": true,
"engines": {
"node": ">=18"
}
@ -2926,6 +2930,7 @@
"integrity": "sha512-VlJEV0fOQ7BExOsHYAGrgbEiZoi8D+Bl2+f6V2RrXerRSylnp+ZBHmPvaIa8cz0Ajx7WO7Z5RqfgYg7ED1nRhA==",
"dev": true,
"license": "BSD-2-Clause",
"peer": true,
"dependencies": {
"@typescript-eslint/scope-manager": "5.62.0",
"@typescript-eslint/types": "5.62.0",
@ -3129,6 +3134,7 @@
"integrity": "sha512-OvQ/2pUDKmgfCg++xsTX1wGxfTaszcHVcTctW4UJB4hibJx2HXxxO5UmVgyjMa+ZDsiaf5wWLXYpRWMmBI0QHg==",
"dev": true,
"license": "MIT",
"peer": true,
"bin": {
"acorn": "bin/acorn"
},
@ -3544,6 +3550,7 @@
}
],
"license": "MIT",
"peer": true,
"dependencies": {
"caniuse-lite": "^1.0.30001688",
"electron-to-chromium": "^1.5.73",
@ -4693,6 +4700,7 @@
"deprecated": "This version is no longer supported. Please see https://eslint.org/version-support for other options.",
"dev": true,
"license": "MIT",
"peer": true,
"dependencies": {
"@eslint-community/eslint-utils": "^4.2.0",
"@eslint-community/regexpp": "^4.6.1",
@ -6250,6 +6258,7 @@
"integrity": "sha512-NIy3oAFp9shda19hy4HK0HRTWKtPJmGdnvywu01nOqNC2vZg+Z+fvJDxpMQA88eb2I9EcafcdjYgsDthnYTvGw==",
"dev": true,
"license": "MIT",
"peer": true,
"dependencies": {
"@jest/core": "^29.7.0",
"@jest/types": "^29.6.3",
@ -7116,6 +7125,7 @@
"integrity": "sha512-Cvc9WUhxSMEo4McES3P7oK3QaXldCfNWp7pl2NNeiIFlCoLr3kfq9kb1fxftiwk1FLV7CvpvDfonxtzUDeSOPg==",
"dev": true,
"license": "MIT",
"peer": true,
"dependencies": {
"cssstyle": "^4.2.1",
"data-urls": "^5.0.0",
@ -9575,6 +9585,7 @@
"integrity": "sha512-GVsDdsbJzzy4S/v3dqWPJ7EfvZJfCHiDqe80IyrF59LYuP+e6U1LJoUqeuqRbwAWoMNoXivMNeNAOf5E22VA1w==",
"dev": true,
"license": "MIT",
"peer": true,
"bin": {
"rollup": "dist/bin/rollup"
},
@ -10527,6 +10538,7 @@
"integrity": "sha512-mI4WrpHsbCIcwT9cF4FZvr80QUeKvsUsUvKDoR+X/7XHQH98xYD8YHZg7ANtz2GtZt/CBq2QJ0thkGJMHfqc1w==",
"dev": true,
"license": "Apache-2.0",
"peer": true,
"bin": {
"tsc": "bin/tsc",
"tsserver": "bin/tsserver"

245
scripts/build-all.sh

@ -0,0 +1,245 @@
#!/bin/bash
# Complete Build Script - Build Everything from Console
# Builds plugin, iOS app, Android app, and all dependencies
#
# Usage:
# ./scripts/build-all.sh [platform]
# Platform options: ios, android, all (default: all)
#
# @author Matthew Raymer
# @version 1.0.0
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
log_info() {
echo -e "${GREEN}[INFO]${NC} $1"
}
log_warn() {
echo -e "${YELLOW}[WARN]${NC} $1"
}
log_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
log_step() {
echo -e "${BLUE}[STEP]${NC} $1"
}
# Get script directory
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
# Parse arguments
PLATFORM="${1:-all}"
# Validate platform
if [[ ! "$PLATFORM" =~ ^(ios|android|all)$ ]]; then
log_error "Invalid platform: $PLATFORM"
log_info "Usage: $0 [ios|android|all]"
exit 1
fi
cd "$PROJECT_ROOT"
log_info "=========================================="
log_info "Complete Build Script"
log_info "Platform: $PLATFORM"
log_info "=========================================="
log_info ""
# Build TypeScript and plugin code
log_step "Building plugin (TypeScript + Native)..."
if ! ./scripts/build-native.sh --platform "$PLATFORM" 2>&1 | tee /tmp/build-native-output.log; then
log_error "Plugin build failed"
log_info ""
log_info "Full build output saved to: /tmp/build-native-output.log"
log_info "View errors: grep -E '(error:|ERROR|FAILED)' /tmp/build-native-output.log"
log_info ""
log_info "Checking for xcodebuild logs..."
if [ -f "/tmp/xcodebuild_device.log" ]; then
log_info "Device build errors:"
grep -E "(error:|warning:)" /tmp/xcodebuild_device.log | head -30
fi
if [ -f "/tmp/xcodebuild_simulator.log" ]; then
log_info "Simulator build errors:"
grep -E "(error:|warning:)" /tmp/xcodebuild_simulator.log | head -30
fi
exit 1
fi
# Build Android
if [[ "$PLATFORM" == "android" || "$PLATFORM" == "all" ]]; then
log_step "Building Android app..."
cd "$PROJECT_ROOT/android"
if [ ! -f "gradlew" ]; then
log_error "Gradle wrapper not found. Run: cd android && ./gradlew wrapper"
exit 1
fi
# Build Android app
if ! ./gradlew :app:assembleDebug; then
log_error "Android build failed"
exit 1
fi
APK_PATH="app/build/outputs/apk/debug/app-debug.apk"
if [ -f "$APK_PATH" ]; then
log_info "✓ Android APK: $APK_PATH"
else
log_error "Android APK not found at $APK_PATH"
exit 1
fi
log_info ""
fi
# Build iOS
if [[ "$PLATFORM" == "ios" || "$PLATFORM" == "all" ]]; then
log_step "Building iOS app..."
cd "$PROJECT_ROOT/ios"
# Check if CocoaPods is installed
if ! command -v pod &> /dev/null; then
log_error "CocoaPods not found. Install with: gem install cocoapods"
exit 1
fi
# Install CocoaPods dependencies
log_step "Installing CocoaPods dependencies..."
if [ ! -f "Podfile.lock" ] || [ "Podfile" -nt "Podfile.lock" ]; then
pod install
else
log_info "CocoaPods dependencies up to date"
fi
# Check if App workspace exists
if [ ! -d "App/App.xcworkspace" ] && [ ! -d "App/App.xcodeproj" ]; then
log_warn "iOS app Xcode project not found"
log_info "The iOS app may need to be initialized with Capacitor"
log_info "Try: cd ios && npx cap sync ios"
log_info ""
log_info "Attempting to build plugin framework only..."
# Build plugin framework only
cd "$PROJECT_ROOT/ios"
if [ -d "DailyNotificationPlugin.xcworkspace" ]; then
WORKSPACE="DailyNotificationPlugin.xcworkspace"
SCHEME="DailyNotificationPlugin"
CONFIG="Debug"
log_step "Building plugin framework for simulator..."
xcodebuild build \
-workspace "$WORKSPACE" \
-scheme "$SCHEME" \
-configuration "$CONFIG" \
-sdk iphonesimulator \
-destination 'generic/platform=iOS Simulator' \
CODE_SIGN_IDENTITY="" \
CODE_SIGNING_REQUIRED=NO \
CODE_SIGNING_ALLOWED=NO || log_warn "Plugin framework build failed (may need Xcode project setup)"
else
log_error "Cannot find iOS workspace or project"
exit 1
fi
else
# Build iOS app
cd "$PROJECT_ROOT/ios/App"
# Determine workspace vs project
if [ -d "App.xcworkspace" ]; then
WORKSPACE="App.xcworkspace"
BUILD_CMD="xcodebuild -workspace"
elif [ -d "App.xcodeproj" ]; then
PROJECT="App.xcodeproj"
BUILD_CMD="xcodebuild -project"
else
log_error "Cannot find iOS workspace or project"
exit 1
fi
SCHEME="App"
CONFIG="Debug"
SDK="iphonesimulator"
log_step "Building iOS app for simulator..."
if [ -n "$WORKSPACE" ]; then
BUILD_OUTPUT=$(xcodebuild build \
-workspace "$WORKSPACE" \
-scheme "$SCHEME" \
-configuration "$CONFIG" \
-sdk "$SDK" \
-destination 'generic/platform=iOS Simulator' \
-derivedDataPath build/derivedData \
CODE_SIGN_IDENTITY="" \
CODE_SIGNING_REQUIRED=NO \
CODE_SIGNING_ALLOWED=NO \
2>&1)
else
BUILD_OUTPUT=$(xcodebuild build \
-project "$PROJECT" \
-scheme "$SCHEME" \
-configuration "$CONFIG" \
-sdk "$SDK" \
-destination 'generic/platform=iOS Simulator' \
-derivedDataPath build/derivedData \
CODE_SIGN_IDENTITY="" \
CODE_SIGNING_REQUIRED=NO \
CODE_SIGNING_ALLOWED=NO \
2>&1)
fi
if echo "$BUILD_OUTPUT" | grep -q "BUILD SUCCEEDED"; then
log_info "✓ iOS app build completed successfully"
# Find built app
APP_PATH=$(find build/derivedData -name "*.app" -type d -path "*/Build/Products/*-iphonesimulator/*.app" | head -1)
if [ -n "$APP_PATH" ]; then
log_info "✓ iOS app bundle: $APP_PATH"
fi
elif echo "$BUILD_OUTPUT" | grep -q "error:"; then
log_error "iOS app build failed"
echo "$BUILD_OUTPUT" | grep -E "(error:|warning:)" | head -20
exit 1
else
log_warn "iOS app build completed with warnings"
echo "$BUILD_OUTPUT" | grep -E "(warning:|error:)" | head -10
fi
fi
log_info ""
fi
log_info "=========================================="
log_info "✅ Build Complete!"
log_info "=========================================="
log_info ""
# Summary
if [[ "$PLATFORM" == "android" || "$PLATFORM" == "all" ]]; then
log_info "Android APK: android/app/build/outputs/apk/debug/app-debug.apk"
log_info "Install: adb install android/app/build/outputs/apk/debug/app-debug.apk"
fi
if [[ "$PLATFORM" == "ios" || "$PLATFORM" == "all" ]]; then
log_info "iOS App: ios/App/build/derivedData/Build/Products/Debug-iphonesimulator/App.app"
log_info "Install: xcrun simctl install booted <APP_PATH>"
fi
log_info ""
log_info "For deployment scripts, see:"
log_info " - scripts/build-and-deploy-native-ios.sh (iOS native app)"
log_info " - test-apps/daily-notification-test/scripts/build-and-deploy-ios.sh (Vue 3 test app)"

161
scripts/build-and-deploy-native-ios.sh

@ -0,0 +1,161 @@
#!/bin/bash
# Native iOS Development App Build and Deploy Script
# Builds and deploys the ios/App development app to iOS Simulator
# Similar to android/app - a simple Capacitor app for plugin development
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
log_info() {
echo -e "${GREEN}[INFO]${NC} $1"
}
log_warn() {
echo -e "${YELLOW}[WARN]${NC} $1"
}
log_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
log_step() {
echo -e "${BLUE}[STEP]${NC} $1"
}
# Get script directory
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
# Check if we're in the project root
if [ ! -d "$PROJECT_ROOT/ios/App" ]; then
log_error "ios/App directory not found"
log_info "This script must be run from the project root directory"
log_info "Usage: cd /path/to/daily-notification-plugin && ./scripts/build-and-deploy-native-ios.sh"
exit 1
fi
# Check prerequisites
log_step "Checking prerequisites..."
if ! command -v xcodebuild &> /dev/null; then
log_error "xcodebuild not found. Install Xcode command line tools:"
log_info " xcode-select --install"
exit 1
fi
if ! command -v pod &> /dev/null; then
log_error "CocoaPods not found. Install with:"
log_info " gem install cocoapods"
exit 1
fi
# Get simulator device (default to iPhone 15 Pro)
SIMULATOR_DEVICE="${1:-iPhone 15 Pro}"
log_info "Using simulator: $SIMULATOR_DEVICE"
# Boot simulator
log_step "Booting simulator..."
if xcrun simctl list devices | grep -q "$SIMULATOR_DEVICE.*Booted"; then
log_info "Simulator already booted"
else
# Try to boot the device
if xcrun simctl boot "$SIMULATOR_DEVICE" 2>/dev/null; then
log_info "✓ Simulator booted"
else
log_warn "Could not boot simulator automatically"
log_info "Opening Simulator app... (you may need to select device manually)"
open -a Simulator
sleep 5
fi
fi
# Build plugin
log_step "Building plugin..."
cd "$PROJECT_ROOT"
if ! ./scripts/build-native.sh --platform ios; then
log_error "Plugin build failed"
exit 1
fi
# Install CocoaPods dependencies
log_step "Installing CocoaPods dependencies..."
cd "$PROJECT_ROOT/ios"
if [ ! -f "Podfile.lock" ] || [ "Podfile" -nt "Podfile.lock" ]; then
pod install
else
log_info "CocoaPods dependencies up to date"
fi
# Build iOS app
log_step "Building native iOS development app..."
cd "$PROJECT_ROOT/ios/App"
WORKSPACE="App.xcworkspace"
SCHEME="App"
CONFIG="Debug"
SDK="iphonesimulator"
if ! xcodebuild -workspace "$WORKSPACE" \
-scheme "$SCHEME" \
-configuration "$CONFIG" \
-sdk "$SDK" \
-destination "platform=iOS Simulator,name=$SIMULATOR_DEVICE" \
-derivedDataPath build/derivedData \
CODE_SIGN_IDENTITY="" \
CODE_SIGNING_REQUIRED=NO \
CODE_SIGNING_ALLOWED=NO \
clean build; then
log_error "iOS app build failed"
exit 1
fi
# Find built app
APP_PATH=$(find build/derivedData -name "*.app" -type d -path "*/Build/Products/*-iphonesimulator/*.app" | head -1)
if [ -z "$APP_PATH" ]; then
log_error "Could not find built app"
log_info "Searching in: build/derivedData"
find build/derivedData -name "*.app" -type d 2>/dev/null | head -5
exit 1
fi
log_info "Found app: $APP_PATH"
# Install app on simulator
log_step "Installing app on simulator..."
if xcrun simctl install booted "$APP_PATH"; then
log_info "✓ App installed"
else
log_error "Failed to install app"
exit 1
fi
# Get bundle identifier
BUNDLE_ID=$(plutil -extract CFBundleIdentifier raw App/Info.plist 2>/dev/null || echo "com.timesafari.dailynotification")
log_info "Bundle ID: $BUNDLE_ID"
# Launch app
log_step "Launching app..."
if xcrun simctl launch booted "$BUNDLE_ID"; then
log_info "✓ App launched"
else
log_warn "App may already be running"
fi
log_info ""
log_info "✅ Build and deploy complete!"
log_info ""
log_info "To view logs:"
log_info " xcrun simctl spawn booted log stream"
log_info ""
log_info "To uninstall app:"
log_info " xcrun simctl uninstall booted $BUNDLE_ID"
log_info ""
log_info "Note: This is the native iOS development app (ios/App)"
log_info "For the Vue 3 test app, use: test-apps/daily-notification-test/scripts/build-and-deploy-ios.sh"

467
scripts/build-native.sh

@ -7,6 +7,7 @@ set -e
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Logging functions
@ -22,6 +23,10 @@ log_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
log_step() {
echo -e "${BLUE}[STEP]${NC} $1"
}
# Validation functions
check_command() {
if ! command -v $1 &> /dev/null; then
@ -31,9 +36,68 @@ check_command() {
}
check_environment() {
# Check for required tools
local platform=$1
# Initialize NVM if available (for Node.js version management)
if [ -s "$HOME/.nvm/nvm.sh" ]; then
log_info "Loading NVM..."
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
[ -s "$NVM_DIR/bash_completion" ] && . "$NVM_DIR/bash_completion"
# Use default Node.js version if available
if [ -f "$NVM_DIR/alias/default" ]; then
DEFAULT_NODE=$(cat "$NVM_DIR/alias/default")
if [ -n "$DEFAULT_NODE" ]; then
nvm use default >/dev/null 2>&1 || true
fi
fi
# Use latest LTS if no default
if ! command -v node &> /dev/null; then
log_info "No default Node.js version set, using latest LTS..."
nvm use --lts >/dev/null 2>&1 || nvm install --lts >/dev/null 2>&1 || true
fi
fi
# Common checks
check_command "node"
check_command "npm"
# Check Node.js version
NODE_VERSION=$(node -v | cut -d. -f1 | tr -d 'v')
if [ -z "$NODE_VERSION" ] || ! [[ "$NODE_VERSION" =~ ^[0-9]+$ ]]; then
log_error "Could not determine Node.js version"
log_error "Please install Node.js: nvm install --lts (if using NVM)"
exit 1
fi
if [ "$NODE_VERSION" -lt 14 ]; then
log_error "Node.js version 14 or higher is required (found: $NODE_VERSION)"
exit 1
fi
# Platform-specific checks
case $platform in
"android")
check_environment_android
;;
"ios")
check_environment_ios
;;
"all")
check_environment_android
check_environment_ios
;;
*)
log_error "Invalid platform: $platform"
exit 1
;;
esac
}
check_environment_android() {
log_step "Checking Android environment..."
check_command "java"
# Check for Gradle Wrapper instead of system gradle
@ -41,31 +105,114 @@ check_environment() {
log_error "Gradle wrapper not found at android/gradlew"
exit 1
fi
# Check Node.js version
NODE_VERSION=$(node -v | cut -d. -f1 | tr -d 'v')
if [ "$NODE_VERSION" -lt 14 ]; then
log_error "Node.js version 14 or higher is required"
# Check Java version (more robust parsing)
JAVA_VERSION_OUTPUT=$(java -version 2>&1 | head -n 1)
if [ -z "$JAVA_VERSION_OUTPUT" ]; then
log_error "Could not determine Java version"
exit 1
fi
# Check Java version
JAVA_VERSION=$(java -version 2>&1 | head -n 1 | cut -d'"' -f2 | cut -d. -f1)
# Try multiple parsing methods for different Java output formats
JAVA_VERSION=$(echo "$JAVA_VERSION_OUTPUT" | grep -oE 'version "([0-9]+)' | grep -oE '[0-9]+' | head -1)
# Fallback: try to extract from "openjdk version" or "java version" format
if [ -z "$JAVA_VERSION" ]; then
JAVA_VERSION=$(echo "$JAVA_VERSION_OUTPUT" | sed -E 's/.*version "([0-9]+).*/\1/' | head -1)
fi
# Validate we got a number
if [ -z "$JAVA_VERSION" ] || ! [[ "$JAVA_VERSION" =~ ^[0-9]+$ ]]; then
log_error "Could not parse Java version from: $JAVA_VERSION_OUTPUT"
log_error "Please ensure Java is installed correctly"
exit 1
fi
if [ "$JAVA_VERSION" -lt 11 ]; then
log_error "Java version 11 or higher is required"
log_error "Java version 11 or higher is required (found: $JAVA_VERSION)"
exit 1
fi
# Check for Android SDK
if [ -z "$ANDROID_HOME" ]; then
log_error "ANDROID_HOME environment variable is not set"
log_error "Set it with: export ANDROID_HOME=/path/to/android/sdk"
exit 1
fi
log_info "✓ Android environment OK (Java $JAVA_VERSION)"
}
check_environment_ios() {
log_step "Checking iOS environment..."
# Check for Xcode command line tools
if ! command -v xcodebuild &> /dev/null; then
log_error "xcodebuild not found. Install Xcode Command Line Tools:"
log_error " xcode-select --install"
exit 1
fi
# Check for CocoaPods
if ! command -v pod &> /dev/null; then
log_error "CocoaPods not found. Install with:"
log_info " gem install cocoapods"
# Check if rbenv is available and suggest reloading
if [ -n "$RBENV_ROOT" ] || [ -d "$HOME/.rbenv" ]; then
log_info "Or if using rbenv, ensure shell is reloaded:"
log_info " source ~/.zshrc # or source ~/.bashrc"
log_info " gem install cocoapods"
fi
# Check if setup script exists
if [ -f "$SCRIPT_DIR/setup-ruby.sh" ]; then
log_info ""
log_info "You can also run the setup script first:"
log_info " ./scripts/setup-ruby.sh"
log_info " gem install cocoapods"
fi
exit 1
fi
# Check for Swift
if ! command -v swift &> /dev/null; then
log_error "Swift compiler not found"
exit 1
fi
# Verify workspace exists
if [ ! -d "ios/DailyNotificationPlugin.xcworkspace" ]; then
log_error "iOS workspace not found: ios/DailyNotificationPlugin.xcworkspace"
exit 1
fi
log_info "✓ iOS environment OK"
}
# Build functions
build_typescript() {
log_info "Building TypeScript..."
# Ensure npm dependencies are installed
if [ ! -d "node_modules" ]; then
log_step "Installing npm dependencies..."
if ! npm install; then
log_error "Failed to install npm dependencies"
exit 1
fi
else
# Check if package.json changed (compare with package-lock.json)
if [ -f "package-lock.json" ] && [ "package.json" -nt "package-lock.json" ]; then
log_step "package.json changed, updating dependencies..."
if ! npm install; then
log_error "Failed to update npm dependencies"
exit 1
fi
fi
fi
npm run clean
if ! npm run build; then
log_error "TypeScript build failed"
@ -149,33 +296,6 @@ build_android() {
# =============================================================================
# AUTOMATIC FIX: capacitor.build.gradle for Plugin Development Projects
# =============================================================================
#
# PROBLEM: The capacitor.build.gradle file is auto-generated by Capacitor CLI
# and includes a line that tries to load a file that doesn't exist in plugin
# development projects:
# apply from: "../capacitor-cordova-android-plugins/cordova.variables.gradle"
#
# WHY THIS HAPPENS:
# - This file is generated by 'npx cap sync', 'npx cap update', etc.
# - It assumes a full Capacitor app with proper plugin integration
# - Plugin development projects don't have the full Capacitor setup
#
# THE FIX:
# - Comment out the problematic line to prevent build failures
# - Add explanatory comment about why it's commented out
# - This fix gets applied automatically every time the build script runs
#
# WHEN THIS FIX GETS OVERWRITTEN:
# - Running 'npx cap sync' will regenerate the file and remove our fix
# - Running 'npx cap update' will regenerate the file and remove our fix
# - Running 'npx cap add android' will regenerate the file and remove our fix
#
# HOW TO RESTORE THE FIX:
# - Run this build script again (it will reapply the fix automatically)
# - Or run: ./scripts/fix-capacitor-build.sh
# - Or manually comment out the problematic line
#
# =============================================================================
if [ -f "app/capacitor.build.gradle" ]; then
if grep -q "^apply from: \"../capacitor-cordova-android-plugins/cordova.variables.gradle\"" "app/capacitor.build.gradle"; then
@ -237,6 +357,243 @@ build_android() {
cd ..
}
build_ios() {
log_info "Building iOS..."
cd ios || exit 1
# Build configuration (define early for validation)
SCHEME="DailyNotificationPlugin"
CONFIG="Release"
WORKSPACE="DailyNotificationPlugin.xcworkspace"
# Install CocoaPods dependencies
log_step "Installing CocoaPods dependencies..."
if [ ! -f "Podfile.lock" ] || [ "Podfile" -nt "Podfile.lock" ] || [ ! -d "Pods" ] || [ ! -d "Pods/Target Support Files" ]; then
log_info "Podfile changed, Podfile.lock missing, or Pods incomplete - running pod install..."
if ! pod install --repo-update; then
log_error "Failed to install CocoaPods dependencies"
exit 1
fi
else
log_info "Podfile.lock is up to date and Pods directory exists, skipping pod install"
fi
# Quick Swift syntax validation (full validation happens during build)
log_step "Validating Swift syntax..."
cd Plugin
SWIFT_FILES=$(find . -name "*.swift" -type f 2>/dev/null)
if [ -z "$SWIFT_FILES" ]; then
log_warn "No Swift files found in Plugin directory"
else
# Use swiftc with iOS SDK for basic syntax check
IOS_SDK=$(xcrun --show-sdk-path --sdk iphoneos 2>/dev/null)
if [ -n "$IOS_SDK" ]; then
for swift_file in $SWIFT_FILES; do
# Quick syntax check without full compilation
if ! swiftc -sdk "$IOS_SDK" -target arm64-apple-ios16.0 -parse "$swift_file" 2>&1 | grep -q "error:"; then
continue
else
log_warn "Syntax check found issues in $swift_file (will be caught during build)"
# Don't exit - let xcodebuild catch real errors
fi
done
else
log_warn "Could not find iOS SDK, skipping syntax validation"
fi
fi
cd ..
# Clean build
log_step "Cleaning iOS build..."
xcodebuild clean \
-workspace "$WORKSPACE" \
-scheme "$SCHEME" \
-configuration "$CONFIG" \
-sdk iphoneos \
-destination 'generic/platform=iOS' \
-quiet || {
log_warn "Clean failed or unnecessary, continuing..."
}
# Check if iOS device platform is available
log_step "Checking iOS device platform availability..."
BUILD_DEVICE=false
if xcodebuild -showsdks 2>&1 | grep -q "iOS.*iphoneos"; then
IOS_SDK_VERSION=$(xcrun --show-sdk-version --sdk iphoneos 2>&1)
log_info "Found iOS SDK: $IOS_SDK_VERSION"
# Check if platform components are installed by trying a list command
# Note: -dry-run is not supported in new build system, so we check SDK availability differently
if xcodebuild -showsdks 2>&1 | grep -q "iphoneos"; then
# Try to validate SDK path exists
SDK_PATH=$(xcrun --show-sdk-path --sdk iphoneos 2>&1)
if [ $? -eq 0 ] && [ -d "$SDK_PATH" ]; then
# Check if we can actually build (by trying to list build settings)
LIST_OUTPUT=$(xcodebuild -workspace "$WORKSPACE" \
-scheme "$SCHEME" \
-destination 'generic/platform=iOS' \
-showBuildSettings 2>&1 | head -5)
if echo "$LIST_OUTPUT" | grep -q "iOS.*is not installed"; then
log_warn "iOS device platform components not installed"
log_info "To install iOS device platform components, run:"
log_info " xcodebuild -downloadPlatform iOS"
log_info "Or via Xcode: Settings > Components > iOS $IOS_SDK_VERSION"
log_info ""
log_info "Building for iOS Simulator instead (sufficient for plugin development)"
else
BUILD_DEVICE=true
fi
else
log_warn "iOS SDK path not accessible: $SDK_PATH"
log_info "Building for iOS Simulator instead"
fi
else
log_warn "iOS device SDK not found in xcodebuild -showsdks"
log_info "Building for iOS Simulator instead"
fi
else
log_warn "iOS SDK not found"
fi
# Build for device (iOS) if available
if [ "$BUILD_DEVICE" = true ]; then
log_step "Building for iOS device (arm64)..."
BUILD_OUTPUT=$(xcodebuild build \
-workspace "$WORKSPACE" \
-scheme "$SCHEME" \
-configuration "$CONFIG" \
-sdk iphoneos \
-destination 'generic/platform=iOS' \
-derivedDataPath build/derivedData \
CODE_SIGN_IDENTITY="" \
CODE_SIGNING_REQUIRED=NO \
CODE_SIGNING_ALLOWED=NO \
2>&1)
BUILD_EXIT_CODE=$?
if echo "$BUILD_OUTPUT" | grep -q "error.*iOS.*is not installed"; then
log_warn "iOS device build failed - platform components not installed"
echo "$BUILD_OUTPUT" > /tmp/xcodebuild_device.log
log_info "Check build log: /tmp/xcodebuild_device.log"
BUILD_DEVICE=false
elif echo "$BUILD_OUTPUT" | grep -q "BUILD FAILED"; then
log_warn "iOS device build failed"
log_info ""
log_info "=== DEVICE BUILD ERRORS ==="
echo "$BUILD_OUTPUT" | grep -E "(error:|warning:|BUILD FAILED)"
echo "$BUILD_OUTPUT" > /tmp/xcodebuild_device.log
log_info ""
log_info "Full build log saved to: /tmp/xcodebuild_device.log"
log_info "View full log: cat /tmp/xcodebuild_device.log"
log_info "Falling back to simulator build..."
BUILD_DEVICE=false
elif echo "$BUILD_OUTPUT" | grep -q "BUILD SUCCEEDED"; then
log_info "✓ iOS device build completed"
elif [ $BUILD_EXIT_CODE -ne 0 ]; then
log_warn "iOS device build failed (exit code: $BUILD_EXIT_CODE)"
log_info ""
log_info "=== DEVICE BUILD ERRORS ==="
echo "$BUILD_OUTPUT" | grep -E "(error:|warning:|BUILD FAILED)"
echo "$BUILD_OUTPUT" > /tmp/xcodebuild_device.log
log_info ""
log_info "Full build log saved to: /tmp/xcodebuild_device.log"
log_info "View full log: cat /tmp/xcodebuild_device.log"
log_info "Falling back to simulator build..."
BUILD_DEVICE=false
else
log_warn "iOS device build completed with warnings"
echo "$BUILD_OUTPUT" > /tmp/xcodebuild_device.log
fi
fi
# Build for simulator
log_step "Building for iOS simulator..."
SIMULATOR_BUILD_OUTPUT=$(xcodebuild build \
-workspace "$WORKSPACE" \
-scheme "$SCHEME" \
-configuration "$CONFIG" \
-sdk iphonesimulator \
-destination 'generic/platform=iOS Simulator' \
-derivedDataPath build/derivedData \
CODE_SIGN_IDENTITY="" \
CODE_SIGNING_REQUIRED=NO \
CODE_SIGNING_ALLOWED=NO \
2>&1)
SIMULATOR_EXIT_CODE=$?
# Save full output to log file
echo "$SIMULATOR_BUILD_OUTPUT" > /tmp/xcodebuild_simulator.log
if echo "$SIMULATOR_BUILD_OUTPUT" | grep -q "BUILD SUCCEEDED"; then
log_info "✓ iOS simulator build completed successfully"
elif echo "$SIMULATOR_BUILD_OUTPUT" | grep -q "error:"; then
log_error "iOS simulator build failed"
log_info ""
log_info "Full error output:"
echo "$SIMULATOR_BUILD_OUTPUT" | grep -E "(error:|warning:)"
log_info ""
log_info "Full build log saved to: /tmp/xcodebuild_simulator.log"
log_info "View full log: cat /tmp/xcodebuild_simulator.log"
log_info "View errors only: grep -E '(error:|warning:)' /tmp/xcodebuild_simulator.log"
exit 1
elif [ $SIMULATOR_EXIT_CODE -ne 0 ]; then
log_error "iOS simulator build failed (exit code: $SIMULATOR_EXIT_CODE)"
log_info ""
log_info "Build output (last 50 lines):"
echo "$SIMULATOR_BUILD_OUTPUT" | tail -50
log_info ""
log_info "Full build log saved to: /tmp/xcodebuild_simulator.log"
log_info "View full log: cat /tmp/xcodebuild_simulator.log"
exit 1
else
log_warn "iOS simulator build completed with warnings"
echo "$SIMULATOR_BUILD_OUTPUT" | grep -E "(warning:|error:)" | head -10
fi
# Find built frameworks
DEVICE_FRAMEWORK=$(find build/derivedData -path "*/Build/Products/*-iphoneos/DailyNotificationPlugin.framework" -type d | head -1)
SIMULATOR_FRAMEWORK=$(find build/derivedData -path "*/Build/Products/*-iphonesimulator/DailyNotificationPlugin.framework" -type d | head -1)
if [ -n "$DEVICE_FRAMEWORK" ]; then
log_info "✓ Device framework: $DEVICE_FRAMEWORK"
fi
if [ -n "$SIMULATOR_FRAMEWORK" ]; then
log_info "✓ Simulator framework: $SIMULATOR_FRAMEWORK"
fi
# Create universal framework (optional)
if [ -n "$DEVICE_FRAMEWORK" ] && [ -n "$SIMULATOR_FRAMEWORK" ]; then
log_step "Creating universal framework..."
UNIVERSAL_DIR="build/universal"
mkdir -p "$UNIVERSAL_DIR"
# Copy device framework
cp -R "$DEVICE_FRAMEWORK" "$UNIVERSAL_DIR/"
# Create universal binary
UNIVERSAL_FRAMEWORK="$UNIVERSAL_DIR/DailyNotificationPlugin.framework/DailyNotificationPlugin"
if lipo -create \
"$DEVICE_FRAMEWORK/DailyNotificationPlugin" \
"$SIMULATOR_FRAMEWORK/DailyNotificationPlugin" \
-output "$UNIVERSAL_FRAMEWORK" 2>/dev/null; then
log_info "✓ Universal framework: $UNIVERSAL_DIR/DailyNotificationPlugin.framework"
else
log_warn "Universal framework creation failed (may not be needed)"
fi
fi
cd ..
log_info "iOS build completed successfully!"
}
# Main build process
main() {
log_info "Starting build process..."
@ -249,35 +606,53 @@ main() {
BUILD_PLATFORM="$2"
shift 2
;;
--help|-h)
echo "Usage: $0 [--platform PLATFORM]"
echo ""
echo "Options:"
echo " --platform PLATFORM Build platform: 'android', 'ios', or 'all' (default: all)"
echo ""
echo "Examples:"
echo " $0 --platform android # Build Android only"
echo " $0 --platform ios # Build iOS only"
echo " $0 --platform all # Build both platforms"
echo " $0 # Build both platforms (default)"
exit 0
;;
*)
log_error "Unknown option: $1"
log_error "Use --help for usage information"
exit 1
;;
esac
done
# Check environment
check_environment
# Check environment (platform-specific)
check_environment "$BUILD_PLATFORM"
# Build TypeScript
build_typescript
# Build based on platform
case $BUILD_PLATFORM in
"android")
build_android
;;
"ios")
build_ios
;;
"all")
build_android
build_ios
;;
*)
log_error "Invalid platform: $BUILD_PLATFORM. Use 'android' or 'all'"
log_error "Invalid platform: $BUILD_PLATFORM. Use 'android', 'ios', or 'all'"
exit 1
;;
esac
log_info "Build completed successfully!"
}
# Run main function with all arguments
main "$@"
main "$@"

250
scripts/setup-ruby.sh

@ -0,0 +1,250 @@
#!/bin/bash
# Ruby Version Manager (rbenv) Setup Script
# Installs rbenv and Ruby 3.1+ for CocoaPods compatibility
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
log_info() {
echo -e "${GREEN}[INFO]${NC} $1"
}
log_warn() {
echo -e "${YELLOW}[WARN]${NC} $1"
}
log_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
log_step() {
echo -e "${BLUE}[STEP]${NC} $1"
}
# Check if rbenv is already installed
if command -v rbenv &> /dev/null; then
log_info "rbenv is already installed"
RBENV_INSTALLED=true
else
log_step "Installing rbenv..."
RBENV_INSTALLED=false
fi
# Install rbenv via Homebrew (recommended on macOS)
if [ "$RBENV_INSTALLED" = false ]; then
if command -v brew &> /dev/null; then
log_info "Installing rbenv via Homebrew..."
brew install rbenv ruby-build
# Initialize rbenv in shell
if [ -n "$ZSH_VERSION" ]; then
SHELL_CONFIG="$HOME/.zshrc"
else
SHELL_CONFIG="$HOME/.bash_profile"
fi
# Add rbenv initialization to shell config
if ! grep -q "rbenv init" "$SHELL_CONFIG" 2>/dev/null; then
log_info "Adding rbenv initialization to $SHELL_CONFIG..."
echo '' >> "$SHELL_CONFIG"
echo '# rbenv initialization' >> "$SHELL_CONFIG"
echo 'eval "$(rbenv init - zsh)"' >> "$SHELL_CONFIG"
fi
# Load rbenv in current session
eval "$(rbenv init - zsh)"
log_info "✓ rbenv installed successfully"
else
log_warn "Homebrew not found. Installing rbenv manually..."
# Manual installation via git
if [ ! -d "$HOME/.rbenv" ]; then
git clone https://github.com/rbenv/rbenv.git ~/.rbenv
fi
if [ ! -d "$HOME/.rbenv/plugins/ruby-build" ]; then
mkdir -p ~/.rbenv/plugins
git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
fi
# Add to PATH
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init - zsh)"
# Add to shell config
if [ -n "$ZSH_VERSION" ]; then
SHELL_CONFIG="$HOME/.zshrc"
else
SHELL_CONFIG="$HOME/.bash_profile"
fi
if ! grep -q "rbenv init" "$SHELL_CONFIG" 2>/dev/null; then
echo '' >> "$SHELL_CONFIG"
echo '# rbenv initialization' >> "$SHELL_CONFIG"
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> "$SHELL_CONFIG"
echo 'eval "$(rbenv init - zsh)"' >> "$SHELL_CONFIG"
fi
log_info "✓ rbenv installed manually"
fi
fi
# Reload shell config
log_step "Reloading shell configuration..."
if [ -n "$ZSH_VERSION" ]; then
source ~/.zshrc 2>/dev/null || true
else
source ~/.bash_profile 2>/dev/null || true
fi
# Ensure rbenv is in PATH
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init - zsh)" 2>/dev/null || eval "$(rbenv init - bash)" 2>/dev/null || true
# Check current Ruby version
log_step "Checking current Ruby version..."
CURRENT_RUBY=$(ruby -v 2>/dev/null | cut -d' ' -f2 | cut -d. -f1,2) || CURRENT_RUBY="unknown"
if [ "$CURRENT_RUBY" != "unknown" ]; then
RUBY_MAJOR=$(echo "$CURRENT_RUBY" | cut -d. -f1)
RUBY_MINOR=$(echo "$CURRENT_RUBY" | cut -d. -f2)
if [ "$RUBY_MAJOR" -ge 3 ] && [ "$RUBY_MINOR" -ge 1 ]; then
log_info "✓ Ruby version $CURRENT_RUBY is already >= 3.1.0"
log_info "You can proceed with CocoaPods installation"
exit 0
else
log_warn "Current Ruby version: $CURRENT_RUBY (needs 3.1.0+)"
fi
fi
# Check if rbenv has a suitable Ruby version already installed
log_step "Checking installed Ruby versions..."
if rbenv versions | grep -qE "3\.(1|2|3|4)\."; then
INSTALLED_RUBY=$(rbenv versions | grep -E "3\.(1|2|3|4)\." | tail -1 | sed 's/^[[:space:]]*//' | cut -d' ' -f1)
log_info "Found installed Ruby version: $INSTALLED_RUBY"
# Set as global if not already set
CURRENT_GLOBAL=$(rbenv global)
if [ "$CURRENT_GLOBAL" != "$INSTALLED_RUBY" ]; then
log_info "Setting $INSTALLED_RUBY as default..."
rbenv global "$INSTALLED_RUBY"
rbenv rehash
fi
# Verify it works
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init - zsh)" 2>/dev/null || eval "$(rbenv init - bash)" 2>/dev/null || true
if ruby -rpsych -e "true" 2>/dev/null; then
VERIFIED_RUBY=$(ruby -v)
log_info "✓ Ruby $VERIFIED_RUBY is working correctly"
log_info ""
log_info "Ruby setup complete!"
log_info ""
log_info "Next steps:"
log_info " 1. Reload your shell: source ~/.zshrc"
log_info " 2. Verify Ruby: ruby -v"
log_info " 3. Install CocoaPods: gem install cocoapods"
exit 0
else
log_warn "Installed Ruby $INSTALLED_RUBY found but psych extension not working"
log_warn "May need to reinstall Ruby or install libyaml dependencies"
fi
fi
# Check for libyaml dependency (required for psych extension)
log_step "Checking for libyaml dependency..."
LIBYAML_FOUND=false
if command -v brew &> /dev/null; then
if brew list libyaml &> /dev/null; then
LIBYAML_FOUND=true
log_info "✓ libyaml found via Homebrew"
else
log_warn "libyaml not installed. Installing via Homebrew..."
if brew install libyaml; then
LIBYAML_FOUND=true
log_info "✓ libyaml installed successfully"
else
log_error "Failed to install libyaml via Homebrew"
fi
fi
else
# Check if libyaml headers exist in system locations
if find /usr/local /opt /Library -name "yaml.h" 2>/dev/null | grep -q yaml.h; then
LIBYAML_FOUND=true
log_info "✓ libyaml headers found in system"
else
log_warn "libyaml not found. Ruby installation may fail."
log_warn "Install libyaml via Homebrew: brew install libyaml"
log_warn "Or install via MacPorts: sudo port install libyaml"
fi
fi
# List available Ruby versions
log_step "Fetching available Ruby versions..."
rbenv install --list | grep -E "^[[:space:]]*3\.[1-9]" | tail -5 || log_warn "Could not fetch Ruby versions list"
# Install Ruby 3.1.0 (preferred for compatibility)
log_step "Installing Ruby 3.1.0..."
if rbenv install 3.1.0; then
log_info "✓ Ruby 3.1.0 installed successfully"
# Set as global default
log_step "Setting Ruby 3.1.0 as default..."
rbenv global 3.1.0
# Verify installation
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init - zsh)" 2>/dev/null || eval "$(rbenv init - bash)" 2>/dev/null || true
NEW_RUBY=$(ruby -v)
log_info "✓ Current Ruby version: $NEW_RUBY"
# Verify psych extension works
if ruby -rpsych -e "true" 2>/dev/null; then
log_info "✓ psych extension verified"
else
log_warn "psych extension may not be working correctly"
log_warn "This may affect CocoaPods installation"
fi
# Rehash to make Ruby available
rbenv rehash
log_info ""
log_info "Ruby setup complete!"
log_info ""
log_info "Next steps:"
log_info " 1. Reload your shell: source ~/.zshrc"
log_info " 2. Verify Ruby: ruby -v"
log_info " 3. Install CocoaPods: gem install cocoapods"
else
log_error "Failed to install Ruby 3.1.0"
if [ "$LIBYAML_FOUND" = false ]; then
log_error ""
log_error "Installation failed. This is likely due to missing libyaml dependency."
log_error ""
log_error "To fix:"
if command -v brew &> /dev/null; then
log_error " brew install libyaml"
else
log_error " Install Homebrew: /bin/bash -c \"\$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)\""
log_error " Then: brew install libyaml"
fi
log_error ""
log_error "After installing libyaml, run this script again."
else
log_error "Installation failed. Please check your internet connection and try again."
fi
exit 1
fi

183
test-apps/daily-notification-test/docs/IOS_BUILD_QUICK_REFERENCE.md

@ -0,0 +1,183 @@
# iOS Build Process Quick Reference
**Author**: Matthew Raymer
**Date**: November 4, 2025
## Two Different Test Apps
**Important**: There are two different iOS test apps:
1. **Native iOS Development App** (`ios/App`) - Simple Capacitor app for quick plugin testing
2. **Vue 3 Test App** (`test-apps/daily-notification-test`) - Full-featured Vue 3 Capacitor app
---
## Vue 3 Test App (`test-apps/daily-notification-test`)
### 🚨 Critical Build Steps
```bash
# 1. Build web assets
npm run build
# 2. Sync with iOS project
npx cap sync ios
# 3. Build iOS app
cd ios/App
xcodebuild -workspace App.xcworkspace \
-scheme App \
-configuration Debug \
-sdk iphonesimulator \
-destination 'platform=iOS Simulator,name=iPhone 15 Pro' \
CODE_SIGN_IDENTITY="" \
CODE_SIGNING_REQUIRED=NO \
CODE_SIGNING_ALLOWED=NO
# 4. Install and launch
APP_PATH=$(find build/derivedData -name "*.app" -type d | head -1)
xcrun simctl install booted "$APP_PATH"
BUNDLE_ID=$(plutil -extract CFBundleIdentifier raw App/Info.plist)
xcrun simctl launch booted "$BUNDLE_ID"
```
### 🔄 Using Capacitor CLI (Simplest Method)
```bash
cd test-apps/daily-notification-test
# Build and run in one command
npx cap run ios
# This handles:
# - Building web assets
# - Syncing with iOS
# - Building app
# - Installing on simulator
# - Launching app
```
### 🛠️ Automated Build Script
```bash
cd test-apps/daily-notification-test
./scripts/build-and-deploy-ios.sh
```
---
## Native iOS Development App (`ios/App`)
### 🚨 Critical Build Steps
```bash
# 1. Build plugin
cd /path/to/daily-notification-plugin
./scripts/build-native.sh --platform ios
# 2. Install CocoaPods dependencies
cd ios
pod install
# 3. Build iOS app
cd App
xcodebuild -workspace App.xcworkspace \
-scheme App \
-configuration Debug \
-sdk iphonesimulator \
-destination 'platform=iOS Simulator,name=iPhone 15 Pro' \
CODE_SIGN_IDENTITY="" \
CODE_SIGNING_REQUIRED=NO \
CODE_SIGNING_ALLOWED=NO
# 4. Install and launch
APP_PATH=$(find build/derivedData -name "*.app" -type d | head -1)
xcrun simctl install booted "$APP_PATH"
BUNDLE_ID=$(plutil -extract CFBundleIdentifier raw App/Info.plist)
xcrun simctl launch booted "$BUNDLE_ID"
```
### 🛠️ Automated Build Script
```bash
cd /path/to/daily-notification-plugin
./scripts/build-and-deploy-native-ios.sh
```
---
## ⚠️ iOS-Specific Requirements
**Prerequisites:**
- macOS (required for iOS development)
- Xcode installed (`xcode-select --install`)
- CocoaPods installed (`gem install cocoapods`)
- iOS Simulator runtime installed
**Common Issues:**
- Simulator not booted: `xcrun simctl boot "iPhone 15 Pro"`
- CocoaPods not installed: `sudo gem install cocoapods`
- Platform components missing: `xcodebuild -downloadPlatform iOS`
## 🔍 Verification Checklist
After build, verify:
### For Vue 3 Test App:
- [ ] Simulator is booted (`xcrun simctl list devices | grep Booted`)
- [ ] CocoaPods dependencies installed (`cd ios && pod install`)
- [ ] Web assets synced (`npx cap sync ios`)
- [ ] App builds successfully (`xcodebuild ...`)
- [ ] App installs on simulator (`xcrun simctl install`)
- [ ] App launches (`xcrun simctl launch`)
### For Native iOS App:
- [ ] Simulator is booted (`xcrun simctl list devices | grep Booted`)
- [ ] Plugin built (`./scripts/build-native.sh --platform ios`)
- [ ] CocoaPods dependencies installed (`cd ios && pod install`)
- [ ] App builds successfully (`xcodebuild ...`)
- [ ] App installs on simulator (`xcrun simctl install`)
- [ ] App launches (`xcrun simctl launch`)
## 📱 Testing Commands
```bash
# List available simulators
xcrun simctl list devices available
# Boot simulator
xcrun simctl boot "iPhone 15 Pro"
# Check if booted
xcrun simctl list devices | grep Booted
# View logs
xcrun simctl spawn booted log stream
# Uninstall app
xcrun simctl uninstall booted com.timesafari.dailynotification.test # Vue 3 app
xcrun simctl uninstall booted com.timesafari.dailynotification # Native app
# Reset simulator
xcrun simctl erase booted
```
## 🐛 Common Issues
| Issue | Symptom | Solution |
|-------|---------|----------|
| Simulator not found | `Unable to find destination` | Run `xcrun simctl list devices` to see available devices |
| CocoaPods error | `pod: command not found` | Install CocoaPods: `gem install cocoapods` |
| Build fails | `No such file or directory` | Run `pod install` in `ios/` directory |
| Signing error | `Code signing required` | Add `CODE_SIGNING_REQUIRED=NO` to xcodebuild command |
| App won't install | `Could not find application` | Verify app path exists and simulator is booted |
| Vue app: assets not syncing | App shows blank screen | Run `npm run build && npx cap sync ios` |
---
**Remember**:
- **Native iOS App** (`ios/App`) = Quick plugin testing, no web build needed
- **Vue 3 Test App** (`test-apps/...`) = Full testing with UI, requires `npm run build`
Use `npx cap run ios` in the Vue 3 test app directory for the simplest workflow!

150
test-apps/daily-notification-test/scripts/build-and-deploy-ios.sh

@ -0,0 +1,150 @@
#!/bin/bash
# iOS Test App Build and Deploy Script
# Builds and deploys the DailyNotification test app to iOS Simulator
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
log_info() {
echo -e "${GREEN}[INFO]${NC} $1"
}
log_warn() {
echo -e "${YELLOW}[WARN]${NC} $1"
}
log_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
log_step() {
echo -e "${BLUE}[STEP]${NC} $1"
}
# Check if we're in the test app directory
if [ ! -f "package.json" ] || [ ! -d "ios" ]; then
log_error "This script must be run from test-apps/daily-notification-test directory"
log_info "Usage: cd test-apps/daily-notification-test && ./scripts/build-and-deploy-ios.sh"
exit 1
fi
# Check prerequisites
log_step "Checking prerequisites..."
if ! command -v xcodebuild &> /dev/null; then
log_error "xcodebuild not found. Install Xcode command line tools:"
log_info " xcode-select --install"
exit 1
fi
if ! command -v pod &> /dev/null; then
log_error "CocoaPods not found. Install with:"
log_info " gem install cocoapods"
exit 1
fi
# Get simulator device (default to iPhone 15 Pro)
SIMULATOR_DEVICE="${1:-iPhone 15 Pro}"
log_info "Using simulator: $SIMULATOR_DEVICE"
# Boot simulator
log_step "Booting simulator..."
if xcrun simctl list devices | grep -q "$SIMULATOR_DEVICE.*Booted"; then
log_info "Simulator already booted"
else
# Try to boot the device
if xcrun simctl boot "$SIMULATOR_DEVICE" 2>/dev/null; then
log_info "✓ Simulator booted"
else
log_warn "Could not boot simulator automatically"
log_info "Opening Simulator app... (you may need to select device manually)"
open -a Simulator
sleep 5
fi
fi
# Build web assets
log_step "Building web assets..."
npm run build
# Sync with iOS
log_step "Syncing with iOS project..."
if ! npx cap sync ios; then
log_error "Failed to sync with iOS project"
exit 1
fi
# Install CocoaPods dependencies
log_step "Installing CocoaPods dependencies..."
cd ios/App
if [ ! -f "Podfile.lock" ] || [ "Podfile" -nt "Podfile.lock" ]; then
pod install
else
log_info "CocoaPods dependencies up to date"
fi
# Build iOS app
log_step "Building iOS app..."
WORKSPACE="App.xcworkspace"
SCHEME="App"
CONFIG="Debug"
SDK="iphonesimulator"
xcodebuild -workspace "$WORKSPACE" \
-scheme "$SCHEME" \
-configuration "$CONFIG" \
-sdk "$SDK" \
-destination "platform=iOS Simulator,name=$SIMULATOR_DEVICE" \
-derivedDataPath build/derivedData \
CODE_SIGN_IDENTITY="" \
CODE_SIGNING_REQUIRED=NO \
CODE_SIGNING_ALLOWED=NO \
clean build
# Find built app
APP_PATH=$(find build/derivedData -name "*.app" -type d -path "*/Build/Products/*-iphonesimulator/*.app" | head -1)
if [ -z "$APP_PATH" ]; then
log_error "Could not find built app"
log_info "Searching in: build/derivedData"
exit 1
fi
log_info "Found app: $APP_PATH"
# Install app on simulator
log_step "Installing app on simulator..."
if xcrun simctl install booted "$APP_PATH"; then
log_info "✓ App installed"
else
log_error "Failed to install app"
exit 1
fi
# Get bundle identifier
BUNDLE_ID=$(plutil -extract CFBundleIdentifier raw App/Info.plist 2>/dev/null || echo "com.timesafari.dailynotification.test")
log_info "Bundle ID: $BUNDLE_ID"
# Launch app
log_step "Launching app..."
if xcrun simctl launch booted "$BUNDLE_ID"; then
log_info "✓ App launched"
else
log_warn "App may already be running"
fi
log_info ""
log_info "✅ Build and deploy complete!"
log_info ""
log_info "To view logs:"
log_info " xcrun simctl spawn booted log stream"
log_info ""
log_info "To uninstall app:"
log_info " xcrun simctl uninstall booted $BUNDLE_ID"
Loading…
Cancel
Save