From 9a8589bb080c1bc0c38b03f7fb7a43515083d8e1 Mon Sep 17 00:00:00 2001 From: Matthew Raymer Date: Tue, 11 Nov 2025 02:13:15 -0800 Subject: [PATCH] feat(ios): implement getExactAlarmStatus and openExactAlarmSettings methods Implemented exact alarm status methods matching Android functionality: getExactAlarmStatus(): - Returns exact alarm scheduling capability information - iOS always supports exact alarms (UNUserNotificationCenter) - Returns supported=true, enabled based on notification authorization - No fallback window needed (exact scheduling always available) - Matches Android API structure openExactAlarmSettings(): - Opens iOS app notification settings - iOS doesn't have separate exact alarm settings like Android - Opens general app settings instead - Provides API compatibility with Android iOS Adaptations: - Exact alarms always supported (no permission needed) - Enabled status based on notification authorization - No fallback window (precise scheduling always available) - Opens app settings instead of exact alarm settings Progress: 32/52 methods implemented (62% complete) --- ios/Plugin/DailyNotificationPlugin.swift | 70 ++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/ios/Plugin/DailyNotificationPlugin.swift b/ios/Plugin/DailyNotificationPlugin.swift index 7bb7a85..20ec425 100644 --- a/ios/Plugin/DailyNotificationPlugin.swift +++ b/ios/Plugin/DailyNotificationPlugin.swift @@ -1278,6 +1278,76 @@ public class DailyNotificationPlugin: CAPPlugin { } } + /** + * Get exact alarm status + * + * Returns detailed information about exact alarm scheduling capability. + * On iOS, exact alarms are always supported via UNUserNotificationCenter. + * + * Equivalent to Android's getExactAlarmStatus method. + */ + @objc func getExactAlarmStatus(_ call: CAPPluginCall) { + print("DNP-PLUGIN: Getting exact alarm status") + + // iOS always supports exact alarms via UNUserNotificationCenter + // Background App Refresh is the closest equivalent to Android's exact alarm permission + // but we can't check it directly - we assume it's enabled if notifications are authorized + notificationCenter.getNotificationSettings { settings in + let notificationsEnabled = settings.authorizationStatus == .authorized + + // iOS supports exact alarms (UNUserNotificationCenter provides precise scheduling) + let supported = true + let enabled = notificationsEnabled // Assume enabled if notifications are authorized + let canSchedule = enabled + let fallbackWindow = "0 minutes" // No fallback needed on iOS - exact scheduling is always available + + let result: [String: Any] = [ + "supported": supported, + "enabled": enabled, + "canSchedule": canSchedule, + "fallbackWindow": fallbackWindow + ] + + print("DNP-PLUGIN: Exact alarm status: supported=\(supported), enabled=\(enabled), canSchedule=\(canSchedule)") + + DispatchQueue.main.async { + call.resolve(result) + } + } + } + + /** + * Open exact alarm settings + * + * Opens iOS notification settings for the app. + * iOS doesn't have separate exact alarm settings like Android. + * + * Equivalent to Android's openExactAlarmSettings method. + */ + @objc func openExactAlarmSettings(_ call: CAPPluginCall) { + print("DNP-PLUGIN: Opening exact alarm settings (iOS: opens app notification settings)") + + // iOS doesn't have separate exact alarm settings + // Open app notification settings instead + if let settingsUrl = URL(string: UIApplication.openSettingsURLString) { + if UIApplication.shared.canOpenURL(settingsUrl) { + UIApplication.shared.open(settingsUrl) { success in + if success { + print("DNP-PLUGIN: Settings opened successfully") + call.resolve() + } else { + print("DNP-PLUGIN: Failed to open settings") + call.reject("Failed to open settings") + } + } + } else { + call.reject("Cannot open settings URL") + } + } else { + call.reject("Invalid settings URL") + } + } + // MARK: - Private Implementation Methods private func setupBackgroundTasks() {