From 6312d953a4d7f69c7e3c8c51cf5ec273af0c1137 Mon Sep 17 00:00:00 2001 From: Matthew Raymer Date: Tue, 11 Nov 2025 22:16:13 -0800 Subject: [PATCH] feat(ios): enhance permission request logging with os_log and NSLog Enhanced permission request logging for better visibility: Logging Enhancements: - Added os.log import and logger definition - Added os_log statements for system-level logging - Added NSLog statements for guaranteed console output - Enhanced print statements with detailed permission status Permission Logging: - Logs when permission request starts - Logs current authorization status before request - Logs authorization result (granted/denied) - Logs detailed permission settings (alert, badge, sound, etc.) - All logs use multiple methods (print, NSLog, os_log) for maximum visibility Fixes: - Permission visibility: Can now see permission requests in system logs - Debugging: Detailed logging helps diagnose permission issues - Console output: Multiple logging methods ensure messages are captured Result: Permission requests and status changes are now fully logged and visible --- ios/Plugin/DailyNotificationPlugin.swift | 28 +++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/ios/Plugin/DailyNotificationPlugin.swift b/ios/Plugin/DailyNotificationPlugin.swift index 8a17c03..802d19f 100644 --- a/ios/Plugin/DailyNotificationPlugin.swift +++ b/ios/Plugin/DailyNotificationPlugin.swift @@ -12,6 +12,7 @@ import UserNotifications import BackgroundTasks import CoreData import UIKit +import os.log /** * iOS implementation of Daily Notification Plugin @@ -24,6 +25,8 @@ import UIKit @objc(DailyNotificationPlugin) public class DailyNotificationPlugin: CAPPlugin { + static let logger = OSLog(subsystem: "com.timesafari.dailynotification", category: "Plugin") + let notificationCenter = UNUserNotificationCenter.current() let backgroundTaskScheduler = BGTaskScheduler.shared let persistenceController = PersistenceController.shared @@ -1274,11 +1277,22 @@ public class DailyNotificationPlugin: CAPPlugin { */ @objc func requestNotificationPermissions(_ call: CAPPluginCall) { print("DNP-PLUGIN: Requesting notification permissions") + NSLog("DNP-PLUGIN: Requesting notification permissions") + os_log("Requesting notification permissions", log: Self.logger, type: .info) // Check current authorization status notificationCenter.getNotificationSettings { settings in + let currentStatus = settings.authorizationStatus + print("DNP-PLUGIN: Current authorization status: \(currentStatus.rawValue)") + NSLog("DNP-PLUGIN: Current authorization status: %d", currentStatus.rawValue) + os_log("Current authorization status: %d", log: Self.logger, type: .info, currentStatus.rawValue) + if settings.authorizationStatus == .authorized { // Already granted + print("DNP-PLUGIN: Permissions already granted") + NSLog("DNP-PLUGIN: Permissions already granted") + os_log("Permissions already granted", log: Self.logger, type: .info) + let result: [String: Any] = [ "status": "granted", "granted": true, @@ -1297,14 +1311,24 @@ public class DailyNotificationPlugin: CAPPlugin { } // Request authorization + print("DNP-PLUGIN: Requesting authorization from user...") + NSLog("DNP-PLUGIN: Requesting authorization from user...") + os_log("Requesting authorization from user", log: Self.logger, type: .info) + self.notificationCenter.requestAuthorization(options: [.alert, .sound, .badge]) { granted, error in DispatchQueue.main.async { if let error = error { print("DNP-PLUGIN: Permission request failed: \(error)") + NSLog("DNP-PLUGIN: Permission request failed: %@", error.localizedDescription) + os_log("Permission request failed: %{public}@", log: Self.logger, type: .error, error.localizedDescription) call.reject("Permission request failed: \(error.localizedDescription)") return } + print("DNP-PLUGIN: Authorization result: granted=\(granted)") + NSLog("DNP-PLUGIN: Authorization result: granted=%d", granted ? 1 : 0) + os_log("Authorization result: granted=%d", log: Self.logger, type: .info, granted ? 1 : 0) + // Get updated settings after request self.notificationCenter.getNotificationSettings { updatedSettings in let result: [String: Any] = [ @@ -1319,7 +1343,9 @@ public class DailyNotificationPlugin: CAPPlugin { ] DispatchQueue.main.async { - print("DNP-PLUGIN: Permission request completed: granted=\(granted)") + print("DNP-PLUGIN: Permission request completed: granted=\(granted), alert=\(updatedSettings.alertSetting == .enabled), badge=\(updatedSettings.badgeSetting == .enabled), sound=\(updatedSettings.soundSetting == .enabled)") + NSLog("DNP-PLUGIN: Permission request completed: granted=%d", granted ? 1 : 0) + os_log("Permission request completed: granted=%d, alert=%d, badge=%d, sound=%d", log: Self.logger, type: .info, granted ? 1 : 0, updatedSettings.alertSetting == .enabled ? 1 : 0, updatedSettings.badgeSetting == .enabled ? 1 : 0, updatedSettings.soundSetting == .enabled ? 1 : 0) call.resolve(result) } }