feat(ios): Enhance battery optimization and notification management
Description: - Add battery status and power state monitoring - Implement adaptive scheduling based on battery levels - Add maintenance worker for background tasks - Enhance logging with structured DailyNotificationLogger - Add configuration management with DailyNotificationConfig - Define constants in DailyNotificationConstants - Improve error handling and recovery mechanisms Testing: - Add comprehensive test coverage for battery optimization - Add test coverage for power state management - Add test coverage for maintenance tasks - Add test coverage for configuration management - Add test coverage for constants validation Documentation: - Add comprehensive file-level documentation - Add method-level documentation - Add test documentation - Add configuration documentation This commit improves the iOS implementation's reliability and battery efficiency by adding robust error handling, logging, and configuration management to make the plugin more maintainable and debuggable.
This commit is contained in:
@@ -16,6 +16,8 @@ import UserNotifications
|
||||
@objc(DailyNotificationPlugin)
|
||||
public class DailyNotificationPlugin: CAPPlugin {
|
||||
private let notificationCenter = UNUserNotificationCenter.current()
|
||||
private let powerManager = DailyNotificationPowerManager.shared
|
||||
private let maintenanceWorker = DailyNotificationMaintenanceWorker.shared
|
||||
|
||||
private var settings: [String: Any] = [
|
||||
"sound": true,
|
||||
@@ -39,6 +41,15 @@ public class DailyNotificationPlugin: CAPPlugin {
|
||||
return
|
||||
}
|
||||
|
||||
// Check battery optimization status
|
||||
let batteryStatus = powerManager.getBatteryStatus()
|
||||
if batteryStatus["level"] as? Int ?? 100 < DailyNotificationConfig.BatteryThresholds.critical {
|
||||
DailyNotificationLogger.shared.log(
|
||||
.warning,
|
||||
"Warning: Battery level is critical"
|
||||
)
|
||||
}
|
||||
|
||||
// Parse time string (HH:mm format)
|
||||
let timeComponents = time.split(separator: ":")
|
||||
guard timeComponents.count == 2,
|
||||
@@ -52,8 +63,8 @@ public class DailyNotificationPlugin: CAPPlugin {
|
||||
|
||||
// Create notification content
|
||||
let content = UNMutableNotificationContent()
|
||||
content.title = call.getString("title") ?? "Daily Notification"
|
||||
content.body = call.getString("body") ?? "Your daily update is ready"
|
||||
content.title = call.getString("title") ?? DailyNotificationConstants.defaultTitle
|
||||
content.body = call.getString("body") ?? DailyNotificationConstants.defaultBody
|
||||
content.sound = call.getBool("sound", true) ? .default : nil
|
||||
|
||||
// Set priority
|
||||
@@ -110,8 +121,16 @@ public class DailyNotificationPlugin: CAPPlugin {
|
||||
// Schedule notification
|
||||
notificationCenter.add(request) { error in
|
||||
if let error = error {
|
||||
DailyNotificationLogger.shared.log(
|
||||
.error,
|
||||
"Failed to schedule notification: \(error.localizedDescription)"
|
||||
)
|
||||
call.reject("Failed to schedule notification: \(error.localizedDescription)")
|
||||
} else {
|
||||
DailyNotificationLogger.shared.log(
|
||||
.info,
|
||||
"Successfully scheduled notification for \(time)"
|
||||
)
|
||||
call.resolve()
|
||||
}
|
||||
}
|
||||
@@ -255,8 +274,25 @@ public class DailyNotificationPlugin: CAPPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
@objc func getBatteryStatus(_ call: CAPPluginCall) {
|
||||
let status = powerManager.getBatteryStatus()
|
||||
call.resolve(status)
|
||||
}
|
||||
|
||||
@objc func getPowerState(_ call: CAPPluginCall) {
|
||||
let state = powerManager.getPowerState()
|
||||
call.resolve(state)
|
||||
}
|
||||
|
||||
@objc func setAdaptiveScheduling(_ call: CAPPluginCall) {
|
||||
let enabled = call.getBool("enabled", true)
|
||||
powerManager.setAdaptiveScheduling(enabled)
|
||||
call.resolve()
|
||||
}
|
||||
|
||||
public override func load() {
|
||||
notificationCenter.delegate = self
|
||||
maintenanceWorker.scheduleNextMaintenance()
|
||||
}
|
||||
|
||||
private func isValidTime(_ time: String) -> Bool {
|
||||
|
||||
Reference in New Issue
Block a user