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:
@@ -12,6 +12,7 @@ import UserNotifications
|
|||||||
import BackgroundTasks
|
import BackgroundTasks
|
||||||
import CoreData
|
import CoreData
|
||||||
import UIKit
|
import UIKit
|
||||||
|
import os.log
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* iOS implementation of Daily Notification Plugin
|
* iOS implementation of Daily Notification Plugin
|
||||||
@@ -24,6 +25,8 @@ import UIKit
|
|||||||
@objc(DailyNotificationPlugin)
|
@objc(DailyNotificationPlugin)
|
||||||
public class DailyNotificationPlugin: CAPPlugin {
|
public class DailyNotificationPlugin: CAPPlugin {
|
||||||
|
|
||||||
|
static let logger = OSLog(subsystem: "com.timesafari.dailynotification", category: "Plugin")
|
||||||
|
|
||||||
let notificationCenter = UNUserNotificationCenter.current()
|
let notificationCenter = UNUserNotificationCenter.current()
|
||||||
let backgroundTaskScheduler = BGTaskScheduler.shared
|
let backgroundTaskScheduler = BGTaskScheduler.shared
|
||||||
let persistenceController = PersistenceController.shared
|
let persistenceController = PersistenceController.shared
|
||||||
@@ -1274,11 +1277,22 @@ public class DailyNotificationPlugin: CAPPlugin {
|
|||||||
*/
|
*/
|
||||||
@objc func requestNotificationPermissions(_ call: CAPPluginCall) {
|
@objc func requestNotificationPermissions(_ call: CAPPluginCall) {
|
||||||
print("DNP-PLUGIN: Requesting notification permissions")
|
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
|
// Check current authorization status
|
||||||
notificationCenter.getNotificationSettings { settings in
|
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 {
|
if settings.authorizationStatus == .authorized {
|
||||||
// Already granted
|
// 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] = [
|
let result: [String: Any] = [
|
||||||
"status": "granted",
|
"status": "granted",
|
||||||
"granted": true,
|
"granted": true,
|
||||||
@@ -1297,14 +1311,24 @@ public class DailyNotificationPlugin: CAPPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Request authorization
|
// 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
|
self.notificationCenter.requestAuthorization(options: [.alert, .sound, .badge]) { granted, error in
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
if let error = error {
|
if let error = error {
|
||||||
print("DNP-PLUGIN: Permission request failed: \(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)")
|
call.reject("Permission request failed: \(error.localizedDescription)")
|
||||||
return
|
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
|
// Get updated settings after request
|
||||||
self.notificationCenter.getNotificationSettings { updatedSettings in
|
self.notificationCenter.getNotificationSettings { updatedSettings in
|
||||||
let result: [String: Any] = [
|
let result: [String: Any] = [
|
||||||
@@ -1319,7 +1343,9 @@ public class DailyNotificationPlugin: CAPPlugin {
|
|||||||
]
|
]
|
||||||
|
|
||||||
DispatchQueue.main.async {
|
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)
|
call.resolve(result)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user