Files
daily-notification-plugin/ios/Plugin
Jose Olarte III 527c075941 fix(ios): improve test script reliability and pending notification detection
Fixed multiple issues in iOS test script and added logging for test compatibility:

Test Script Fixes:
- Fixed get_simulator_id() to correctly extract UUID from booted devices
- Fixed get_app_logs() to use log show (historical) instead of log stream (live) to avoid hanging
- Improved check_plugin_configured() with multiple detection methods (app container, app listing, data directory)
- Added ensure_plugin_configured() function matching Android pattern for consistent user interaction flow
- Fixed integer comparison error in booted device check (removed newlines from count)
- Removed 'local' keyword from variables in main script body (local can only be used in functions)
- Fixed APP_BUNDLE_ID to match actual bundle identifier

Pending Notification Detection:
- Improved get_pending_notifications() to parse pendingCount from plugin logs
- Added direct log query without restrictive predicate to catch plugin logs
- Added multiple fallback methods for detecting pending count

Plugin Logging Enhancement:
- Added explicit pendingCount logging in DailyNotificationScheduler after scheduling
- Uses both NSLog() and print() to ensure logs appear in system logs and Xcode console
- Matches Android's alarm count logging pattern for test script compatibility

This resolves script crashes and enables reliable detection of pending notifications
for automated testing.
2025-12-11 20:12:34 +08:00
..

iOS Implementation

This directory contains the iOS-specific implementation of the DailyNotification plugin.

Last Updated: 2025-12-08
Version: 1.1.0

Current Implementation Status

IMPLEMENTED:

  • Basic plugin structure (DailyNotificationPlugin.swift)
  • UserDefaults for local data storage
  • Power management (DailyNotificationPowerManager.swift)
  • Battery optimization handling
  • iOS notification categories and actions
  • App Launch Recovery (DailyNotificationReactivationManager.swift)
    • Cold start recovery
    • Termination recovery
    • Boot recovery
    • Scenario detection
    • Missed notification detection
    • Future notification verification
  • Core Data Integration
    • NotificationContent, NotificationDelivery, NotificationConfig entities
    • DAO classes for all entities (CRUD operations)
    • Data type conversions (Date ↔ Int64, etc.)
    • PersistenceController with entity verification
  • Logging & Observability
    • Comprehensive recovery logging
    • Metrics recording in Core Data History
    • Execution time tracking
  • Error Handling
    • iOS-specific error codes
    • Graceful error handling (non-fatal)
    • Partial results on failures
  • API Methods
    • iOS-specific notification permission methods
    • Background task status methods
    • Pending notifications query

⚠️ PARTIALLY IMPLEMENTED:

  • BGTaskScheduler for background data fetching (basic registration)
  • Background task management (needs enhancement)

NOT IMPLEMENTED (Planned):

  • Silent push nudge support
  • Tlead prefetch logic (enhancement)

Implementation Details

The iOS implementation currently uses:

  • UNUserNotificationCenter for notification management
  • UserDefaults for local data storage
  • iOS notification categories and actions
  • Power management and battery optimization
  • Core Data for structured data persistence
  • BGTaskScheduler for background task registration
  • App Launch Recovery for notification reconciliation

Architecture:

  • ReactivationManager: Handles app launch recovery scenarios
  • DAO Layer: Core Data access objects for all entities
  • Data Conversions: Type conversion utilities (Date, Int, String, JSON)
  • History Recording: Core Data persistence for recovery metrics
  • Error Handling: Comprehensive error codes and graceful degradation

Planned additions:

  • Enhanced background task management
  • Silent push support

Native Code Location

The native iOS implementation is located in the ios/ directory at the project root.

Key Components

  1. DailyNotificationPlugin.swift: Main plugin class
  2. DailyNotificationPowerManager.swift: Power state management
  3. DailyNotificationConfig.swift: Configuration options
  4. DailyNotificationMaintenanceWorker.swift: Maintenance tasks
  5. DailyNotificationLogger.swift: Logging system
  6. DailyNotificationReactivationManager.swift: App launch recovery
  7. HistoryDAO.swift: Recovery history persistence
  8. NotificationContentDAO.swift: Notification content CRUD
  9. NotificationDeliveryDAO.swift: Delivery tracking CRUD
  10. NotificationConfigDAO.swift: Configuration CRUD
  11. DailyNotificationDataConversions.swift: Type conversion utilities
  12. DailyNotificationErrorCodes.swift: iOS-specific error codes
  13. DailyNotificationModel.swift: Core Data model & PersistenceController

Background Task Components:

  • DailyNotificationBackgroundTasks.swift: Background task handlers ⚠️ (basic)
  • DailyNotificationBackgroundTaskManager.swift: Task management ⚠️ (basic)

Implementation Notes

  • Uses UserDefaults for lightweight data storage
  • Uses Core Data for structured data persistence
  • Implements proper battery optimization handling
  • Supports iOS notification categories and actions
  • Handles background refresh limitations
  • App launch recovery with scenario detection
  • Comprehensive error handling (non-fatal)
  • Metrics recording and observability
  • BGTaskScheduler registration

Recovery Scenarios Supported:

  • Cold Start: App terminated, notifications may need verification
  • Termination: App terminated, all notifications cleared
  • Boot: Device rebooted, full recovery needed
  • Warm Start: No recovery needed (optimization)

Planned Features:

  • Enhanced background task budget management
  • Silent push notification support
  • Advanced prefetch logic

Testing

Run iOS-specific tests with:

npm run test:ios