fix some scheduling references that we broken, one for androis and one for ios
This commit is contained in:
@@ -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
|
* Check if an alarm is scheduled for a given trigger time
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -381,7 +381,7 @@ public class DailyNotificationPlugin: CAPPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@objc func scheduleUserNotification(_ call: CAPPluginCall) {
|
@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")
|
call.reject("User notification config required")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user