Commit Graph

10 Commits

Author SHA1 Message Date
Jose Olarte III
d2a1041cc4 feat(ios): add missed rollover recovery for background/inactive app scenarios
Implement enhanced app launch recovery to detect and schedule missed rollover
notifications that occurred while the app was terminated, backgrounded, or
inactive.

Key improvements:
- Detect missed rollovers on app launch by checking for past notifications
  without next scheduled notification
- Add active rollover check when app becomes active (handles inactive app
  scenario where notifications fire silently)
- Calculate forward to future time when next scheduled time is in the past
  (handles delays > rollover interval)
- Enhance duplicate detection to exclude original notification from checks
- Retry rollover if previous attempt failed (rollover time set but no next
  notification exists)

Changes:
- DailyNotificationReactivationManager: Add detectAndProcessMissedRollovers()
  method and performActiveRolloverCheck() for app becoming active
- DailyNotificationReactivationManager: Enhance warm start scenario to check
  for missed rollovers
- DailyNotificationScheduler: Add forward calculation loop when next scheduled
  time is in the past
- DailyNotificationPlugin: Register observer for UIApplication.didBecomeActiveNotification
  to trigger rollover check when app becomes active

Fixes rollover scheduling for:
- App terminated: Rollover now detected and scheduled on next launch
- App inactive/backgrounded: Rollover detected when app becomes active
- Delayed recovery: Handles cases where app reopened after rollover interval
  has passed by calculating forward to next future time

All scenarios now properly schedule rollover notifications regardless of app
state when notification fires.
2026-01-09 20:02:40 +08:00
Matthew Raymer
36f2c095db feat(ios): add deliveryStatus and lastDeliveryAttempt to NotificationContent
Complete final 2 Phase 2 iOS enhancements - delivery tracking properties.

Changes:
- NotificationContent: Add delivery tracking properties
  - deliveryStatus: String? (e.g., "scheduled", "delivered", "missed", "error")
  - lastDeliveryAttempt: Int64? (milliseconds since epoch)
  - Updated Codable support (CodingKeys, init, encode)
  - Updated toDictionary/fromDictionary for backward compatibility
  - Properties are optional with default nil (backward compatible)
- DailyNotificationReactivationManager: Use delivery tracking
  - detectMissedNotifications(): Filter by deliveryStatus != "delivered"
  - markMissedNotification(): Set deliveryStatus="missed" and lastDeliveryAttempt
  - Removed 2 TODOs, fully implemented

Phase 2 Progress: 8 of 8 enhancements COMPLETE 
-  Rolling window maintenance
-  TTL validation
-  Database statistics
-  Metrics recording
-  CoreData history
-  Fetcher instances clarified
-  deliveryStatus property (this commit)
-  lastDeliveryAttempt property (this commit)

Verification:
- TypeScript typecheck: PASS
- Tests: PASS (115 tests, 8 test suites)
- No linter errors
- Backward compatible (optional parameters with defaults)
2025-12-24 07:38:12 +00:00
Matthew Raymer
a070ec9f0b feat(ios): complete remaining Phase 2 enhancements
Implement CoreData history and clarify fetcher parameter usage.

Changes:
- DailyNotificationBackgroundTasks: Implement CoreData history recording
  - recordHistory(): Now uses PersistenceController and History.create()
  - Records kind and outcome to CoreData History entity
  - Removed TODO, fully implemented
- DailyNotificationPlugin: Clarify fetcher parameter
  - Updated comment: fetcher parameter is unused
  - fetchScheduler handles prefetch scheduling (already implemented)
- DailyNotificationReactivationManager: Clarify fetcher parameter
  - Updated comment: fetcher parameter is unused
  - fetchScheduler handles prefetch scheduling (already implemented)

Phase 2 Progress: 6 of 8 enhancements complete
-  Rolling window maintenance
-  TTL validation
-  Database statistics
-  Metrics recording
-  CoreData history (this commit)
-  Fetcher instances clarified (this commit)
-  NotificationContent properties (deliveryStatus, lastDeliveryAttempt) - requires model changes

Verification:
- TypeScript typecheck: PASS
- Tests: PASS (115 tests, 8 test suites)
- No linter errors
2025-12-24 07:32:43 +00:00
Matthew Raymer
bae7438f76 feat(android,ios): P3.1-C Instrument recovery paths with timing
Added timing instrumentation to recovery functions:

Android (ReactivationManager.kt):
- performColdStartRecovery(): Added startTime tracking and duration logging
- performForceStopRecovery(): Added startTime tracking and duration logging

iOS (DailyNotificationReactivationManager.swift):
- performColdStartRecovery(): Added startTime tracking and duration logging

All recovery functions now log duration in milliseconds with operation counts.

Verification:
- TypeScript compiles 
- Android builds (if available) 
- No behavior changes (recovery still idempotent) 
2025-12-23 06:38:56 +00:00
Jose Olarte III
0a2cbf24f7 fix(ios): correct next notification time and improve rollover UI refresh
- Fix getNextNotificationTime() to find earliest scheduled notification
  instead of using first request (pendingNotificationRequests doesn't
  guarantee order)
- Add comprehensive logging for rollover tracking with DNP-ROLLOVER
  prefix for Xcode console filtering
- Reset all notifications and rollover state when scheduling new
  notification via scheduleDailyNotification() to ensure clean test
  state
- Fix userInfo scope error in handleNotificationDelivery error handler
- Update test app UI to refresh status every 5-10 seconds and
  immediately after notification delivery to reflect rollover changes
- Add console logging in UI to debug getNotificationStatus() results

This ensures the UI correctly displays the next notification time after
rollover completes, and test notifications start with a clean slate.
2025-12-15 21:42:48 +08:00
Jose Olarte III
1bfd87a0e4 fix(ios): resolve build errors and add missing configureNativeFetcher method
Fixed Swift compilation errors preventing iOS build:
- Added explicit self capture [self] in closures in DailyNotificationReactivationManager
- Removed invalid BGTaskScheduler.shared.registeredTaskIdentifiers API call
- Fixed initialization order in DailyNotificationModel (verifyEntities after container init)

Added missing configureNativeFetcher method to iOS plugin:
- Implemented method matching Android functionality
- Stores configuration in UserDefaults for persistence
- Registered method in pluginMethods array
- Supports both jwtToken and jwtSecret parameters for compatibility

This resolves the runtime error "configureNativeFetcher is not a function"
that was preventing the test app from configuring the plugin.
2025-12-11 16:44:18 +08:00
Matthew
332dfbad75 feat(ios): enhance background task handlers and documentation
Enhance background task handlers with recovery logic and comprehensive
code documentation:

Background Task Handlers (Section 3.3):
- Enhance handleBackgroundFetch with recovery logic:
  - Verify scheduled notifications after fetch
  - Schedule next background task automatically
  - Improved expiration handling with graceful cleanup
- Enhance handleBackgroundNotify with recovery logic:
  - Verify scheduled notifications state
  - Prepare for next task scheduling
  - Improved expiration handling with graceful cleanup
- Add getNextScheduledNotificationTime() helper method
  - Wraps scheduler.getNextNotificationTime() with timeout
  - Used for automatic next task scheduling

Code Documentation (Section 10.1):
- Add comprehensive file-level documentation to ReactivationManager:
  - Purpose, features, architecture overview
  - Recovery scenarios supported
  - Error handling approach
  - Thread safety notes
  - Cross-references to requirements docs
- Add detailed method-level documentation:
  - performRecovery(): process, scenarios, error handling
  - detectScenario(): detection logic, error handling
  - performColdStartRecovery(): steps, return values
  - detectMissedNotifications(): criteria, error handling
  - verifyFutureNotifications(): verification process
  - rescheduleMissingNotification(): process, throws
  - handleTerminationRecovery(): comprehensive recovery
  - performBootRecovery(): boot recovery process
  - recordRecoveryHistory(): history recording
  - recordRecoveryFailure(): failure recording
  - detectBootScenario(): detection logic
  - updateLastLaunchTime(): storage details
  - verifyBGTaskRegistration(): diagnostic method
- Add @param, @return, @throws tags to all methods
- Document error handling behavior for all methods

Implementation Status (Section 10.2):
- Update ios/Plugin/README.md with current status:
  - Mark all completed features as 
  - Add new components (DAO classes, ReactivationManager)
  - Update version to 1.1.0
  - Add recovery scenarios supported
  - Update architecture overview
  - Add last updated date (2025-12-08)

Completes sections 3.3, 10.1, and 10.2 of iOS implementation checklist.
2025-12-09 19:09:07 -08:00
Matthew
3649e76c49 feat(ios): add error handling and integration tests
Implement comprehensive error handling and integration test suite:

Error Handling (Section 8):
- Add iOS-specific error codes to DailyNotificationErrorCodes:
  - NOTIFICATION_PERMISSION_DENIED
  - PENDING_NOTIFICATION_LIMIT_EXCEEDED
  - BG_TASK_NOT_REGISTERED
  - BG_TASK_EXECUTION_FAILED
  - BACKGROUND_REFRESH_DISABLED
- Add helper methods for iOS-specific error responses
- Enhance error handling in ReactivationManager:
  - Database errors handled gracefully (non-fatal)
  - Notification center errors handled gracefully (non-fatal)
  - Scheduling errors handled gracefully (non-fatal)
  - All errors logged, app continues normally
  - Partial results returned when operations fail
- Update plugin methods to use iOS-specific error codes:
  - getNotificationPermissionStatus uses NOTIFICATION_PERMISSION_DENIED

Integration Tests (Section 9.2):
- Add DailyNotificationRecoveryIntegrationTests:
  - Full recovery flow tests (cold start, termination)
  - Error handling tests (database, notification center, scheduling)
  - App stability tests (no crashes, concurrent operations)
  - Partial recovery tests
  - Timeout handling tests
- Test coverage:
  - 10 integration tests covering recovery scenarios
  - Error handling verification
  - App stability verification
  - Concurrent operation safety

Completes sections 8.1, 8.2, and 9.2 of iOS implementation checklist.
2025-12-09 02:46:13 -08:00
Matthew
12d8536588 feat(ios): enhance recovery logging and metrics recording
Implement comprehensive logging and observability for recovery operations:

- Add HistoryDAO for Core Data history recording
  - recordRecovery() method with execution time tracking
  - recordRecoveryFailure() method with detailed error info
  - Query helpers for history retrieval
- Enhance DailyNotificationReactivationManager logging:
  - Add execution time tracking (startTime/endTime)
  - Enhanced error logging with NSError details (domain, code, userInfo)
  - Comprehensive logging at each recovery step
  - Missed/future notification count logging
- Implement Core Data persistence for recovery metrics:
  - Recovery execution time
  - Missed notification count
  - Rescheduled notification count
  - Verified notification count
  - Error count
  - Diagnostic JSON with full recovery context
- Update recovery methods to record history:
  - Cold start recovery
  - Termination recovery
  - Boot recovery
  - All with timing and metrics

Completes section 7.1 (Recovery Logging) and 7.2 (Metrics Recording)
of iOS implementation checklist.
2025-12-09 02:37:27 -08:00
Matthew
a90d08c425 feat(ios): add Core Data DAO layer and unit tests
Implement comprehensive data access layer for Core Data entities:

- Add NotificationContentDAO, NotificationDeliveryDAO, and NotificationConfigDAO
  with full CRUD operations and query helpers
- Add DailyNotificationDataConversions utility for type conversions
  (Date ↔ Int64, Int ↔ Int32, JSON, optional strings)
- Update PersistenceController with entity verification and migration policies
- Add comprehensive unit tests for all DAO classes and data conversions
- Update Core Data model with NotificationContent, NotificationDelivery,
  and NotificationConfig entities (relationships and indexes)
- Integrate ReactivationManager into DailyNotificationPlugin.load()

DAO Features:
- Create/Insert methods with dictionary support
- Read/Query methods with predicates (by timesafariDid, notificationType,
  scheduledTime range, deliveryStatus, etc.)
- Update methods (touch, updateDeliveryStatus, recordUserInteraction)
- Delete methods (by ID, by key, delete all)
- Relationship management (NotificationContent ↔ NotificationDelivery)
- Cascade delete support

Test Coverage:
- 328 lines: DailyNotificationDataConversionsTests (time, numeric, string, JSON)
- 490 lines: NotificationContentDAOTests (CRUD, queries, updates)
- 415 lines: NotificationDeliveryDAOTests (CRUD, relationships, cascade delete)
- 412 lines: NotificationConfigDAOTests (CRUD, queries, active filtering)

All tests use in-memory Core Data stack for isolation and speed.

Completes sections 4.4, 4.5, and 6.0 of iOS implementation checklist.
2025-12-09 02:23:05 -08:00