diff --git a/local-notifications/android/src/main/java/com/capacitorjs/plugins/localnotifications/LocalNotificationManager.java b/local-notifications/android/src/main/java/com/capacitorjs/plugins/localnotifications/LocalNotificationManager.java index 0b826a546..ba5dde3ae 100644 --- a/local-notifications/android/src/main/java/com/capacitorjs/plugins/localnotifications/LocalNotificationManager.java +++ b/local-notifications/android/src/main/java/com/capacitorjs/plugins/localnotifications/LocalNotificationManager.java @@ -332,8 +332,15 @@ private void triggerScheduledNotification(Notification notification, LocalNotifi } PendingIntent pendingIntent = PendingIntent.getBroadcast(context, request.getId(), notificationIntent, flags); - // Schedule at specific time (with repeating support) Date at = schedule.getAt(); + String every = schedule.getEvery(); + DateMatch on = schedule.getOn(); + if ((at != null ? 0 : 1) + (every != null ? 0 : 1) + (on != null ? 0 : 1) <= 1) { + Logger.error(Logger.tags("LN"), "You cannot use multiple scheduler types. Use either 'at', 'every' or 'on' in the schedule object.", null); + return; + } + + // Schedule at specific time (with repeating support) if (at != null) { if (at.getTime() < new Date().getTime()) { Logger.error(Logger.tags("LN"), "Scheduled time must be *after* current time", null); @@ -349,7 +356,6 @@ private void triggerScheduledNotification(Notification notification, LocalNotifi } // Schedule at specific intervals - String every = schedule.getEvery(); if (every != null) { Long everyInterval = schedule.getEveryInterval(); if (everyInterval != null) { @@ -360,7 +366,6 @@ private void triggerScheduledNotification(Notification notification, LocalNotifi } // Cron like scheduler - DateMatch on = schedule.getOn(); if (on != null) { long trigger = on.nextTrigger(new Date()); notificationIntent.putExtra(TimedNotificationPublisher.CRON_KEY, on.toMatchString()); diff --git a/local-notifications/ios/Sources/LocalNotificationsPlugin/LocalNotificationsPlugin.swift b/local-notifications/ios/Sources/LocalNotificationsPlugin/LocalNotificationsPlugin.swift index 463be9a12..6ccb0335c 100644 --- a/local-notifications/ios/Sources/LocalNotificationsPlugin/LocalNotificationsPlugin.swift +++ b/local-notifications/ios/Sources/LocalNotificationsPlugin/LocalNotificationsPlugin.swift @@ -284,6 +284,11 @@ public class LocalNotificationsPlugin: CAPPlugin, CAPBridgedPlugin { let on = schedule["on"] as? JSObject let repeats = schedule["repeats"] as? Bool ?? false + if (at != nil ? 1 : 0) + (on != nil ? 1 : 0) + (every != nil ? 1 : 0) <= 1 { + call.reject("You cannot use multiple scheduler types. Use either 'at', 'every' or 'on' in the schedule object.") + return nil + } + // If there's a specific date for this notificiation if let at = at { let dateInfo = Calendar.current.dateComponents(in: TimeZone.current, from: at)