TheAlmightyBob / Calendars

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

Plugin.Calendars.Abstractions.PlatformException: The calendar is read only. ---> Foundation.NSErrorException: Exception of type 'Foundation.NSErrorException' was thrown. #30

Closed jamal-deen-EB closed 7 years ago

jamal-deen-EB commented 7 years ago

I have added the NuGet plugin into my Xamrin Forms project. I could add the events into my Android default google calendar mobile app, but when I run the same code into iOS project it is showing the below exception in Plugin.Calendars.Abstractions.PlatformException: The calendar is read only. ---> Foundation.NSErrorException: Exception of type 'Foundation.NSErrorException' was thrown. in these lines.

var calendars = await CrossCalendars.Current.GetCalendarsAsync();
                if (calendars.Count > 0)
                    await CrossCalendars.Current.AddOrUpdateEventAsync(calendars[0], _event);
TheAlmightyBob commented 7 years ago

This is most likely a difference in the calendars you are using, not a difference in platforms. You can check the CanEditEvents property of the calendar before calling AddOrUpdateEventsAsync on it.

Simply adding to the first calendar in the list of calendars is probably not what you want...