diff --git a/Source/Plugin.LocalNotification/NotificationRepeat.cs b/Source/Plugin.LocalNotification/NotificationRepeat.cs index efad0cf9..3bcbf93a 100644 --- a/Source/Plugin.LocalNotification/NotificationRepeat.cs +++ b/Source/Plugin.LocalNotification/NotificationRepeat.cs @@ -18,6 +18,11 @@ public enum NotificationRepeat /// /// Notification should repeat next week at same day, same time /// - Weekly + Weekly, + + /// + /// Notification to be delivered after the specified amount of time elapses + /// + TimeInterval } } \ No newline at end of file diff --git a/Source/Plugin.LocalNotification/NotificationRequest.cs b/Source/Plugin.LocalNotification/NotificationRequest.cs index 94a86fcb..450b8e85 100644 --- a/Source/Plugin.LocalNotification/NotificationRequest.cs +++ b/Source/Plugin.LocalNotification/NotificationRequest.cs @@ -35,7 +35,12 @@ public class NotificationRequest public DateTime? NotifyTime { get; set; } /// - /// If true, will repeat again at the time specifies in NotifyTime. + /// if Repeats = TimeInterval, then repeat again after specified amount of time elapses + /// + public TimeSpan? NotifyRepeatInterval { get; set; } + + /// + /// If true, will repeat again at the time specifies in NotifyTime or NotifyRepeatInterval /// public NotificationRepeat Repeats { get; set; } = NotificationRepeat.No; diff --git a/Source/Plugin.LocalNotification/Platform/Droid/ScheduledNotificationWorker.cs b/Source/Plugin.LocalNotification/Platform/Droid/ScheduledNotificationWorker.cs index 0b43fdd8..ad82d61c 100644 --- a/Source/Plugin.LocalNotification/Platform/Droid/ScheduledNotificationWorker.cs +++ b/Source/Plugin.LocalNotification/Platform/Droid/ScheduledNotificationWorker.cs @@ -56,7 +56,6 @@ public override Result DoWork() { notification.NotifyTime = notification.NotifyTime.Value.AddDays(1); } - break; case NotificationRepeat.Weekly: @@ -66,7 +65,18 @@ public override Result DoWork() { notification.NotifyTime = notification.NotifyTime.Value.AddDays(7); } + break; + case NotificationRepeat.TimeInterval: + if (notification.NotifyRepeatInterval.HasValue) + { + notification.NotifyTime = + notification.NotifyTime.Value.Add(notification.NotifyRepeatInterval.Value); + while (notification.NotifyTime <= DateTime.Now) + { + notification.NotifyTime = notification.NotifyTime.Value.Add(notification.NotifyRepeatInterval.Value); + } + } break; } diff --git a/Source/Plugin.LocalNotification/Platform/iOS/NotificationServiceImpl.cs b/Source/Plugin.LocalNotification/Platform/iOS/NotificationServiceImpl.cs index 48980bca..8cab4d99 100644 --- a/Source/Plugin.LocalNotification/Platform/iOS/NotificationServiceImpl.cs +++ b/Source/Plugin.LocalNotification/Platform/iOS/NotificationServiceImpl.cs @@ -65,6 +65,7 @@ public void CancelAll() /// public async void Show(NotificationRequest notificationRequest) { + UNNotificationTrigger trigger = null; try { if (UIDevice.CurrentDevice.CheckSystemVersion(10, 0) == false) @@ -108,8 +109,20 @@ public async void Show(NotificationRequest notificationRequest) } var repeats = notificationRequest.Repeats != NotificationRepeat.No; - using var notifyTime = GetNsDateComponentsFromDateTime(notificationRequest); - using var trigger = UNCalendarNotificationTrigger.CreateTrigger(notifyTime, repeats); + + if (repeats && notificationRequest.Repeats == NotificationRepeat.TimeInterval && + notificationRequest.NotifyRepeatInterval.HasValue) + { + var seconds = notificationRequest.NotifyRepeatInterval.Value.TotalSeconds; + + trigger = UNTimeIntervalNotificationTrigger.CreateTrigger(seconds, true); + } + else + { + using var notifyTime = GetNsDateComponentsFromDateTime(notificationRequest); + trigger = UNCalendarNotificationTrigger.CreateTrigger(notifyTime, repeats); + } + var notificationId = notificationRequest.NotificationId.ToString(CultureInfo.CurrentCulture); @@ -122,6 +135,10 @@ await UNUserNotificationCenter.Current.AddNotificationRequestAsync(request) { Debug.WriteLine(ex); } + finally + { + trigger?.Dispose(); + } } private static NSDateComponents GetNsDateComponentsFromDateTime(NotificationRequest notificationRequest)