diff --git a/ios/Plugin/DailyNotificationPlugin.swift b/ios/Plugin/DailyNotificationPlugin.swift index 515d9e9..5306f5d 100644 --- a/ios/Plugin/DailyNotificationPlugin.swift +++ b/ios/Plugin/DailyNotificationPlugin.swift @@ -81,6 +81,9 @@ public class DailyNotificationPlugin: CAPPlugin { object: nil ) + NSLog("DNP-ROLLOVER: Observer registered for DailyNotificationDelivered notification") + print("DNP-ROLLOVER: Observer registered for DailyNotificationDelivered notification") + NSLog("DNP-DEBUG: DailyNotificationPlugin.load() completed - initialization done") print("DNP-PLUGIN: Daily Notification Plugin loaded on iOS") @@ -1405,13 +1408,22 @@ public class DailyNotificationPlugin: CAPPlugin { * @param notification NSNotification with userInfo containing notification_id and scheduled_time */ @objc private func handleNotificationDelivery(_ notification: Notification) { + NSLog("DNP-ROLLOVER: handleNotificationDelivery called") + print("DNP-ROLLOVER: handleNotificationDelivery called") + // Extract notification data from userInfo guard let userInfo = notification.userInfo, let notificationId = userInfo["notification_id"] as? String, let scheduledTime = userInfo["scheduled_time"] as? Int64 else { + NSLog("DNP-ROLLOVER: ERROR handleNotificationDelivery missing required data userInfo=%@", userInfo ?? "nil") + print("DNP-ROLLOVER: ERROR handleNotificationDelivery missing required data userInfo=\(userInfo ?? [:])") return } + let scheduledTimeStr = formatTime(scheduledTime) + NSLog("DNP-ROLLOVER: handleNotificationDelivery processing id=%@ scheduled_time=%@", notificationId, scheduledTimeStr) + print("DNP-ROLLOVER: handleNotificationDelivery processing id=\(notificationId) scheduled_time=\(scheduledTimeStr)") + // Track notify execution let currentTime = Int64(Date().timeIntervalSince1970 * 1000) storage?.saveLastNotifyExecution(timestamp: currentTime) @@ -1429,15 +1441,33 @@ public class DailyNotificationPlugin: CAPPlugin { * @param scheduledTime Scheduled time of delivered notification */ private func processRollover(notificationId: String, scheduledTime: Int64) async { + let scheduledTimeStr = formatTime(scheduledTime) + NSLog("DNP-ROLLOVER: processRollover START id=%@ scheduled_time=%@", notificationId, scheduledTimeStr) + print("DNP-ROLLOVER: processRollover START id=\(notificationId) scheduled_time=\(scheduledTimeStr)") + guard let scheduler = scheduler, let storage = storage else { + NSLog("DNP-ROLLOVER: ERROR processRollover missing scheduler or storage scheduler=%@ storage=%@", + scheduler != nil ? "present" : "nil", storage != nil ? "present" : "nil") + print("DNP-ROLLOVER: ERROR processRollover missing scheduler or storage scheduler=\(scheduler != nil ? "present" : "nil") storage=\(storage != nil ? "present" : "nil")") return } // Get the notification content that was delivered guard let content = storage.getNotificationContent(id: notificationId) else { + NSLog("DNP-ROLLOVER: ERROR processRollover content not found in storage id=%@", notificationId) + print("DNP-ROLLOVER: ERROR processRollover content not found in storage id=\(notificationId)") + + // Log available notification IDs for debugging + let allNotifications = storage.getAllNotifications() + let availableIds = allNotifications.map { $0.id }.joined(separator: ", ") + NSLog("DNP-ROLLOVER: Available notification IDs in storage: [%@]", availableIds) + print("DNP-ROLLOVER: Available notification IDs in storage: [\(availableIds)]") return } + NSLog("DNP-ROLLOVER: processRollover found content id=%@ calling scheduleNextNotification", notificationId) + print("DNP-ROLLOVER: processRollover found content id=\(notificationId) calling scheduleNextNotification") + // Delegate to scheduler to schedule next notification (glue logic - will be moved to service) // Note: fetcher parameter is unused - scheduler uses fetchScheduler instead (already implemented) let scheduled = await scheduler.scheduleNextNotification( @@ -1446,8 +1476,15 @@ public class DailyNotificationPlugin: CAPPlugin { fetcher: nil // Unused - fetchScheduler handles prefetch scheduling ) + if scheduled { + NSLog("DNP-ROLLOVER: processRollover SUCCESS id=%@ next notification scheduled", notificationId) + print("DNP-ROLLOVER: processRollover SUCCESS id=\(notificationId) next notification scheduled") + } else { + NSLog("DNP-ROLLOVER: processRollover FAILED id=%@ scheduleNextNotification returned false", notificationId) + print("DNP-ROLLOVER: processRollover FAILED id=\(notificationId) scheduleNextNotification returned false") + } + // Rollover processing is non-fatal - recovery will handle on next launch if needed - _ = scheduled } /**