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
This commit is contained in:
Matthew Raymer
2025-11-11 22:16:13 -08:00
parent 977080bc2d
commit 6312d953a4

View File

@@ -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)
}
}