TheAlmightyBob / Calendars

Cross-platform calendar API plugin for Xamarin and Windows
MIT License
101 stars 23 forks source link

Interface to get the default calendar #49

Open jorgenstorlie opened 6 years ago

jorgenstorlie commented 6 years ago

I want to get the default calendar, found s sample here:

https://github.com/xamarinhq/app-conference/blob/master/src/Conference.Clients.Portable/Services/ReminderService.cs

but this returned the first calendar with the user can modify.

Changed this:

static async Task GetOrCreateConferenceCalendarAsync()

Added:

                string DefaultCalendarIdentifier = "";

if IOS

                var _eventStore = new EKEventStore();
                var ddd = _eventStore.DefaultCalendarForNewEvents;
                if (ddd != null)
                    DefaultCalendarIdentifier = ddd.CalendarIdentifier;

endif

                foreach (var calendar in calendars)
                {

                    //find first calendar default
                    if (calendar.ExternalID != DefaultCalendarIdentifier)
                        continue;

                    //find first calendar we can add stuff to
                    if (!calendar.CanEditEvents)
                        continue;

                    ConferenceCalendarId = calendar.ExternalID;
                    return calendar;
                }

This seems to work, but it would have been nice to have a interface that return the default calendar.