async void ScheduleReminderNotification(TriggeredReminder reminder, int badge) { UNMutableNotificationContent content = new UNMutableNotificationContent() { Title = reminder.Appointment.Subject, Body = CreateMessageContent(reminder), Sound = UNNotificationSound.Default, Badge = badge, }; NSDateComponents dateComponents = new NSDateComponents() { Second = reminder.AlertTime.Second, Minute = reminder.AlertTime.Minute, Hour = reminder.AlertTime.Hour, Day = reminder.AlertTime.Day, Month = reminder.AlertTime.Month, Year = reminder.AlertTime.Year, TimeZone = NSTimeZone.SystemTimeZone, }; UNCalendarNotificationTrigger trigger = UNCalendarNotificationTrigger.CreateTrigger(dateComponents, false); string identifier = NotificationCenter.SerializeReminder(reminder); UNNotificationRequest request = UNNotificationRequest.FromIdentifier(identifier, content, trigger); await notificationCenter.AddNotificationRequestAsync(request); }
public async Task CreateDailyReminders(List <PlantActivityItem>[] listOfTasksForEveryDay, byte atHour = 8, byte atMinute = 0) { //First, remove all still pending notifications. await RemoveDailyReminders(); //Create notifications for each day. for (int i = 0; i < listOfTasksForEveryDay.Count(); i++) { var date = DateTime.Now.AddDays(i); NSDateComponents dateComponents = new NSDateComponents { Year = date.Year, Month = date.Month, Day = date.Day, Hour = atHour, Minute = atMinute }; var trigger = UNCalendarNotificationTrigger.CreateTrigger(dateComponents, false); var content = new UNMutableNotificationContent { Sound = UNNotificationSound.Default, CategoryIdentifier = DAILY_NOTIFICATIONS, }; if (listOfTasksForEveryDay[i].Count == 0) { content.Title = "All good!"; content.Body = "You have no tasks for today. Enjoy the freedom! 😎"; } else { content.Title = "Your plants need you!"; content.Body = $"You have {listOfTasksForEveryDay[i].Count} task{(listOfTasksForEveryDay[i].Count > 1 ? "s" : "")} for today. Tap to see what you have to do in order to keep your (hopefully still) green friends happy. 🌿🌺"; } var request = UNNotificationRequest.FromIdentifier( $"Daily_Notification_{date.Year}_{date.Month}_{date.Day}", content, trigger); await NotificationCenter.AddNotificationRequestAsync(request); } }