EddyVerbruggen / Calendar-PhoneGap-Plugin

:date: Cordova plugin to Create, Change, Delete and Find Events in the native Calendar
774 stars 403 forks source link

XCode 15 cordova-ios@7.0.1 : Calendars list returns nothing #565

Open hooliapps opened 8 months ago

hooliapps commented 8 months ago

Hello, i installed the last XCode 15 on Ventura (ios min version 11) / iOS 17 / cordova-ios@7.0.1

Plugin don't crash but don't show any calendar.

I get the warning message "accept or not", but after list is empty.

Do you have any idea please ? (Worked since long time)

<plugin name="cordova-plugin-calendar" spec="5.1.6">
    <variable name="CALENDAR_USAGE_DESCRIPTION" value="Export hours to calendar" />
</plugin>

<edit-config target="NSCalendarsUsageDescription" file="*-Info.plist" mode="merge">
    <string>Synchronize planning with calendar</string>
</edit-config>

window.plugins.calendar.listCalendars(openCalendarsListSuccess, openCalendarsListError); I get openCalendarsListSuccess response, but the calendars list is empty.

kallewangstedt commented 8 months ago

I have the same issue. When fetching all calendars by window.plugins.calendar.listCalendars() it returns an empty array. When using window.plugins.calendar.findEvent() it returns the error No default calendar found. Is access to the Calendar blocked for this app?

There is a default calendar set and the app has full access to the calendars.

kallewangstedt commented 8 months ago

Fix for this problem can be found in this PR: https://github.com/EddyVerbruggen/Calendar-PhoneGap-Plugin/pull/566

hooliapps commented 8 months ago

Thanks a lot i will test asap.

hooliapps commented 8 months ago

I confirm that your solution + JS code work perfectly without changing anything in cordova.xml

I just need to changed my code to call your functions.

Tested on XCode 15 / iOS 17 / iPhone 13 Pro Max.

Not tested on any other version or XCode.

hooliapps commented 8 months ago

Finally, i retested by deleting the App then reisntalling with Testflight but dont works anymore.

I think we need to add new Permissions in cordova.

image

matfantinel commented 8 months ago

For the record, the cause of this are likely the changes in iOS 17 highlighted here.

For those using Capacitor, you might need to add NSCalendarsFullAccessUsageDescription to Info.plist as well, although I haven't tried with the code in the PR yet.

kallewangstedt commented 8 months ago

The README states that for iOS10+ you need to provide a reason in the plist.

sjregan commented 8 months ago

I've created a new pull request to address some of the issues.

Thanks @kallewangstedt for your original pull request which mine is based on.

My pull request also allows write only access to be requested for the calendar. However, this does create a potential issue where requests might fail if the following is done in this order:

  1. Request full calendar access
  2. Request write only calendar access
  3. Execute read calendar request

I don't actually know how to write Objective C, so I would do a proper review and tests of my pull request.

I could solve the above issue if someone can explain the following to me:

Why is self.eventStore used in some places: https://github.com/sjregan/Calendar-PhoneGap-Plugin/blob/2b309a9ea7769f69bb40cae9552673a83187a1d6/src/ios/Calendar.m#L331C60-L331C71

e.g.

datedEvents = [self.eventStore eventsMatchingPredicate:[eventStore predicateForEventsWithStartDate:startDate endDate:endDate calendars:calendars]];

And not others? https://github.com/sjregan/Calendar-PhoneGap-Plugin/blob/2b309a9ea7769f69bb40cae9552673a83187a1d6/src/ios/Calendar.m#L526

NSPredicate *fetchCalendarEvents = [eventStore predicateForEventsWithStartDate:startDate endDate:endDate calendars:calendarArray];

Is this a bug, or a deliberate choice for some reason?