fix(ios): add diagnostic logging for rollover notification flow
Add comprehensive logging to trace rollover notification handling from AppDelegate delivery through to next notification scheduling. This enables diagnosis of why rollover notifications fail to schedule the next 24-hour notification. Changes: - Log observer registration on plugin load - Log handler entry and data extraction in handleNotificationDelivery - Log processing steps in processRollover including: * Missing scheduler/storage detection * Content lookup failures with available IDs * ScheduleNextNotification success/failure These logs will help identify whether the issue is: - Observer not receiving notifications - Content missing from storage - Scheduling logic failing silently
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user