feat(ios): implement updateDualScheduleConfig, cancelDualSchedule, pauseDualSchedule, and resumeDualSchedule methods
Implemented dual schedule management methods: updateDualScheduleConfig(): - Updates dual schedule configuration - Cancels existing schedules and reschedules with new config - Stores config in UserDefaults for persistence - Combines content fetch and user notification scheduling cancelDualSchedule(): - Cancels all dual schedule notifications - Clears stored dual schedule config - Uses existing cancelAllNotifications method pauseDualSchedule(): - Pauses dual schedule by cancelling notifications - Stores pause state in UserDefaults - Allows resuming later with stored config resumeDualSchedule(): - Resumes paused dual schedule - Restores from stored config in UserDefaults - Re-schedules both content fetch and user notification - Validates pause state before resuming iOS Adaptations: - Uses UserDefaults for config persistence - Pause/resume pattern for schedule management - Config restoration on resume Progress: 36/52 methods implemented (69% complete)
This commit is contained in:
@@ -122,6 +122,99 @@ public class DailyNotificationPlugin: CAPPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
@objc func updateDualScheduleConfig(_ call: CAPPluginCall) {
|
||||
guard let config = call.getObject("config"),
|
||||
let contentFetchConfig = config["contentFetch"] as? [String: Any],
|
||||
let userNotificationConfig = config["userNotification"] as? [String: Any] else {
|
||||
call.reject("Dual notification config required")
|
||||
return
|
||||
}
|
||||
|
||||
print("DNP-PLUGIN: Updating dual schedule config")
|
||||
|
||||
// Cancel existing schedules first
|
||||
cancelAllNotifications(call)
|
||||
|
||||
// Schedule new configuration
|
||||
do {
|
||||
try scheduleBackgroundFetch(config: contentFetchConfig)
|
||||
try scheduleUserNotification(config: userNotificationConfig)
|
||||
|
||||
// Store config in UserDefaults
|
||||
if let configData = try? JSONSerialization.data(withJSONObject: config, options: []),
|
||||
let configString = String(data: configData, encoding: .utf8) {
|
||||
UserDefaults.standard.set(configString, forKey: "DailyNotificationDualScheduleConfig")
|
||||
UserDefaults.standard.synchronize()
|
||||
}
|
||||
|
||||
call.resolve()
|
||||
} catch {
|
||||
print("DNP-PLUGIN: Failed to update dual schedule config: \(error)")
|
||||
call.reject("Dual schedule config update failed: \(error.localizedDescription)")
|
||||
}
|
||||
}
|
||||
|
||||
@objc func cancelDualSchedule(_ call: CAPPluginCall) {
|
||||
print("DNP-PLUGIN: Cancelling dual schedule")
|
||||
|
||||
// Cancel all notifications (this cancels both fetch and notify)
|
||||
cancelAllNotifications(call)
|
||||
|
||||
// Clear stored config
|
||||
UserDefaults.standard.removeObject(forKey: "DailyNotificationDualScheduleConfig")
|
||||
UserDefaults.standard.synchronize()
|
||||
|
||||
print("DNP-PLUGIN: Dual schedule cancelled")
|
||||
}
|
||||
|
||||
@objc func pauseDualSchedule(_ call: CAPPluginCall) {
|
||||
print("DNP-PLUGIN: Pausing dual schedule")
|
||||
|
||||
// Store pause state
|
||||
UserDefaults.standard.set(true, forKey: "DailyNotificationDualSchedulePaused")
|
||||
UserDefaults.standard.synchronize()
|
||||
|
||||
// Cancel all notifications (they can be resumed later)
|
||||
cancelAllNotifications(call)
|
||||
|
||||
print("DNP-PLUGIN: Dual schedule paused")
|
||||
call.resolve()
|
||||
}
|
||||
|
||||
@objc func resumeDualSchedule(_ call: CAPPluginCall) {
|
||||
print("DNP-PLUGIN: Resuming dual schedule")
|
||||
|
||||
// Check if paused
|
||||
guard UserDefaults.standard.bool(forKey: "DailyNotificationDualSchedulePaused") else {
|
||||
call.reject("Dual schedule is not paused")
|
||||
return
|
||||
}
|
||||
|
||||
// Clear pause state
|
||||
UserDefaults.standard.set(false, forKey: "DailyNotificationDualSchedulePaused")
|
||||
UserDefaults.standard.synchronize()
|
||||
|
||||
// Restore from stored config if available
|
||||
if let configString = UserDefaults.standard.string(forKey: "DailyNotificationDualScheduleConfig"),
|
||||
let configData = configString.data(using: .utf8),
|
||||
let config = try? JSONSerialization.jsonObject(with: configData) as? [String: Any],
|
||||
let contentFetchConfig = config["contentFetch"] as? [String: Any],
|
||||
let userNotificationConfig = config["userNotification"] as? [String: Any] {
|
||||
do {
|
||||
try scheduleBackgroundFetch(config: contentFetchConfig)
|
||||
try scheduleUserNotification(config: userNotificationConfig)
|
||||
print("DNP-PLUGIN: Dual schedule resumed from stored config")
|
||||
call.resolve()
|
||||
} catch {
|
||||
print("DNP-PLUGIN: Failed to resume dual schedule: \(error)")
|
||||
call.reject("Dual schedule resume failed: \(error.localizedDescription)")
|
||||
}
|
||||
} else {
|
||||
print("DNP-PLUGIN: No stored config found, cannot resume")
|
||||
call.reject("No stored dual schedule config found")
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Main Scheduling Method
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user