/// <summary> /// Adds an event reminder to specified calendar event /// </summary> /// <param name="calendarEvent">Event to add the reminder to</param> /// <param name="reminder">The reminder</param> /// <returns>Success or failure</returns> /// <exception cref="ArgumentException">If calendar event is not created or not valid</exception> /// <exception cref="Calendars.Plugin.Abstractions.PlatformException">Unexpected platform-specific error</exception> public Task<bool> AddEventReminderAsync(CalendarEvent calendarEvent, CalendarEventReminder reminder) { if (string.IsNullOrEmpty(calendarEvent.ExternalID)) { throw new ArgumentException("Missing calendar event identifier", "calendarEvent"); } //Grab current event var existingEvent = _eventStore.EventFromIdentifier(calendarEvent.ExternalID); if (existingEvent == null) { throw new ArgumentException("Specified calendar event not found on device"); } // var seconds = -reminder?.TimeBefore.TotalSeconds ?? defaultTimeBefore; var alarm = EKAlarm.FromTimeInterval(seconds); existingEvent.AddAlarm(alarm); NSError error = null; if (!_eventStore.SaveEvent(existingEvent, EKSpan.ThisEvent, out error)) { // Without this, the eventStore will continue to return the "updated" // event even though the save failed! // (this obviously also resets any other changes, but since we own the eventStore // we can be pretty confident that won't be an issue) // _eventStore.Reset(); throw new ArgumentException(error.LocalizedDescription, "reminder", new NSErrorException(error)); } return Task.FromResult(true); }
/// <summary> /// Not supported for Windows Store apps /// </summary> public Task<bool> AddEventReminderAsync(CalendarEvent calendarEvent, CalendarEventReminder reminder) { throw new NotSupportedException(); }
/// <summary> /// Adds an event reminder to specified calendar event /// </summary> /// <param name="calendarEvent">Event to add the reminder to</param> /// <param name="reminder">The reminder</param> /// <returns>Success or failure</returns> /// <exception cref="ArgumentException">If calendar event is not created or not valid</exception> /// <exception cref="Calendars.Plugin.Abstractions.PlatformException">Unexpected platform-specific error</exception> public async Task<bool> AddEventReminderAsync(CalendarEvent calendarEvent, CalendarEventReminder reminder) { if (string.IsNullOrEmpty(calendarEvent.ExternalID)) { throw new ArgumentException("Missing calendar event identifier", "calendarEvent"); } // Verify calendar event exists var existingAppt = await GetEventByIdAsync(calendarEvent.ExternalID).ConfigureAwait(false); if (existingAppt == null) { throw new ArgumentException("Specified calendar event not found on device"); } return await Task.Run(() => { var reminderValues = new ContentValues(); reminderValues.Put(CalendarContract.Reminders.InterfaceConsts.Minutes, reminder?.TimeBefore.TotalMinutes ?? 15); reminderValues.Put(CalendarContract.Reminders.InterfaceConsts.EventId, calendarEvent.ExternalID); switch(reminder.Method) { case CalendarReminderMethod.Alert: reminderValues.Put(CalendarContract.Reminders.InterfaceConsts.Method, (int)RemindersMethod.Alert); break; case CalendarReminderMethod.Default: reminderValues.Put(CalendarContract.Reminders.InterfaceConsts.Method, (int)RemindersMethod.Default); break; case CalendarReminderMethod.Email: reminderValues.Put(CalendarContract.Reminders.InterfaceConsts.Method, (int)RemindersMethod.Email); break; case CalendarReminderMethod.Sms: reminderValues.Put(CalendarContract.Reminders.InterfaceConsts.Method, (int)RemindersMethod.Sms); break; } var uri = CalendarContract.Reminders.ContentUri; Insert(uri, reminderValues); return true; }); }
/// <summary> /// Adds an event reminder to specified calendar event /// </summary> /// <param name="calendarEvent">Event to add the reminder to</param> /// <param name="reminder">The reminder</param> /// <returns>Success or failure</returns> /// <exception cref="ArgumentException">If calendar event is not created or not valid</exception> /// <exception cref="Calendars.Plugin.Abstractions.PlatformException">Unexpected platform-specific error</exception> public async Task<bool> AddEventReminderAsync(CalendarEvent calendarEvent, CalendarEventReminder reminder) { if (string.IsNullOrEmpty(calendarEvent.ExternalID)) { throw new ArgumentException("Missing calendar event identifier", "calendarEvent"); } var existingAppt = await _localApptStore.GetAppointmentAsync(calendarEvent.ExternalID); if (existingAppt == null) { throw new ArgumentException("Specified calendar event not found on device"); } var appCalendar = await _localApptStore.GetAppointmentCalendarAsync(existingAppt.CalendarId); if(appCalendar == null) { throw new ArgumentException("Event does not have a valid calendar."); } existingAppt.Reminder = reminder?.TimeBefore ?? TimeSpan.FromMinutes(15); await appCalendar.SaveAppointmentAsync(existingAppt); return true; }