fix some scheduling references that we broken, one for androis and one for ios

This commit is contained in:
2026-06-22 12:47:26 -06:00
parent d8715340c0
commit ea29219dc2
2 changed files with 58 additions and 2 deletions

View File

@@ -1256,6 +1256,62 @@ open class DailyNotificationPlugin : Plugin() {
}
}
@PluginMethod
fun scheduleUserNotification(call: PluginCall) {
try {
if (context == null) {
return call.reject("Context not available")
}
if (!canScheduleExactAlarms(context)) {
Log.i(TAG, "Exact alarm permission not granted; scheduling will use inexact/windowed fallback.")
}
val options = call.data ?: return call.reject("Options are required")
val schedule = options.getString("schedule") ?: return call.reject("schedule (cron expression) is required")
val title = options.getString("title") ?: "Daily Notification"
val body = options.getString("body") ?: ""
val sound = options.getBoolean("sound") ?: true
val priority = options.getString("priority") ?: "default"
Log.i(TAG, "Scheduling user notification: schedule=$schedule, title=$title")
CoroutineScope(Dispatchers.IO).launch {
try {
val config = UserNotificationConfig(
enabled = true,
schedule = schedule,
title = title,
body = body,
sound = sound,
vibration = true,
priority = priority
)
val scheduleId = ScheduleHelper.scheduleUserNotification(
context,
getDatabase(),
config,
::calculateNextRunTime
)
if (scheduleId != null) {
call.resolve()
} else {
call.reject("User notification scheduling failed")
}
} catch (e: Exception) {
Log.e(TAG, "Failed to schedule user notification", e)
call.reject("User notification scheduling failed: ${e.message}")
}
}
} catch (e: Exception) {
Log.e(TAG, "Schedule user notification error", e)
call.reject("User notification error: ${e.message}")
}
}
/**
* Check if an alarm is scheduled for a given trigger time
*/

View File

@@ -381,11 +381,11 @@ public class DailyNotificationPlugin: CAPPlugin {
}
@objc func scheduleUserNotification(_ call: CAPPluginCall) {
guard let config = call.getObject("config") else {
guard let config = call.options as? [String: Any] else {
call.reject("User notification config required")
return
}
do {
// Delegate to user notification scheduler
try scheduleUserNotification(config: config)