Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API MISUSE: nil event store in initialization of EKCalendar instance for createEventInteractivelyWithOptions #564

Open
KaiserRuben opened this issue Jul 26, 2023 · 9 comments

Comments

@KaiserRuben
Copy link

KaiserRuben commented Jul 26, 2023

Description

For some reason, it seems like I don't have access to the Calendar on iOS. I added 'Privacy - Calendars Usage Description' to Info.plist, so this shouldn't be it.

Android works fine.

Version

iOS 17
Xcode 15.0 beta 3
package.json (excerpt):

{
  "dependencies": {
    "@awesome-cordova-plugins/calendar": "^6.4.0",
    "@awesome-cordova-plugins/core": "^6.4.0",
    "@capacitor/ios": "^4.8.1",
    "@ionic/core": "^7.0.0",
    "vue": "^3.2.47"
  }
}

I have the same behaviour for iOS 16 and Xcode 14 as well.

Logs

Xcode Log:

To Native Cordova ->  Calendar hasReadWritePermission Calendar1008503186 ["options": []]
To Native Cordova ->  Calendar listCalendars Calendar1008503187 ⚡️  [log] - **Has Calendar Permission: false**
["options": []]
⚡️  [log] - Calendars found: []
To Native Cordova ->  Calendar createCalendar Calendar1008503188 ⚡️  [log] - Calendar not found, creating it
["options": [{
    calendarColor = "#0D0cfb";
    calendarName = myCalendar;
}]]
⚡️  [log] - Calendar created: {"id":"71E75CCC-22BF-4386-BE9E-89924B276D40"}
XPC connection was invalidated
No match found for calendar with name: myCalendar
**API MISUSE: nil event store in initialization of EKCalendar instance**
created calendar: myCalendar

Code

I have a function called getCalendar which gets the calendar for me, and, if it does not exist yet, creates it. For testing I added Calendar.hasReadWritePermission(), which should always be true on iOS, but it is not...? This can be seen in the Xcode log.

JavaScript:

import {Calendar} from "@awesome-cordova-plugins/calendar";
export async function getCalendar(): Promise<{ id: (string | undefined) } | null> {
    if (isPlatform('android')) {
        //...
    }
    try {
        const hasPermission = await Calendar.hasReadWritePermission()
        console.log('Has Calendar Permission: ' + hasPermission)

        const calendars = await Calendar.listCalendars()
        console.log('Calendars found: ' + JSON.stringify(calendars))
        let calendar = calendars.find((c: any) => c.name === 'KultNow')

        if (!calendar) {
            console.log('Calendar not found, creating it')
            calendar = {}
            calendar.id = await Calendar.createCalendar({
                calendarName: 'myCalendar',
                calendarColor: '#0D0cfb',
            })

            console.log('Calendar created: ' + JSON.stringify(calendar));
        }
        return calendar
    } catch (e) {
        console.warn('Could not get calendars, maybe no permissions?')
        return null
    }
}
//...
await Calendar.createEventInteractivelyWithOptions(event.name, event.place, event.description, new Date(event.startDate), new Date(event.startDate), options)

Thanks for your help

I'd be thankful for any hints on what I missed.

@KaiserRuben
Copy link
Author

KaiserRuben commented Jul 26, 2023

Update

Requesting Permissions

I tried requesting permission with Calendar.requestReadWritePermission(), but it does not work, as can be seen in the Xcode log...

Code

        try {
            await Calendar.requestReadWritePermission()
        } catch (e) {
            console.log('Could not request permission')
        }

Log

⚡️  [log] - Could not request permission

"It runs on my device"

Cause it actually does work on some iPhones, I did some further testing: Turns out, on iOS 15.5, the Code works. Seems like Apple changed their APIs somewhere in-between iOS 15.5 and iOS 16.

@vicjune
Copy link

vicjune commented Sep 25, 2023

I think this has something to do with API changes for iOS 17:
https://developer.apple.com/documentation/technotes/tn3153-adopting-api-changes-for-eventkit-in-ios-macos-and-watchos

@VittorioCineca
Copy link

I confirm the issue due to the use of XCode 15. Using XCode 14 seems not to reproduce the issue.

@ipehimanshu
Copy link

Hello

so what is solution to fix it ?

Thank you for help

@VittorioCineca
Copy link

By now I got back to XCode 14 to get some extra time, until April.

I'm trying to use the native ICS file import, without success by now.
https://www.reddit.com/r/PWA/comments/gqc3g4/add_to_calendar_on_pwa/

@VittorioCineca
Copy link

Hello

so what is solution to fix it ?

Thank you for help

I found this fork that works:
https://github.com/digistorm/Calendar-PhoneGap-Plugin

This pull request changed less code but doesn't work on my project.
#570

@ipehimanshu
Copy link

ipehimanshu commented Feb 28, 2024 via email

@ipehimanshu
Copy link

hello

does anyone have solution to make it working,

our app stop working for ios totally as it not adding calendar event

Thank you

@VittorioCineca
Copy link

@ipehimanshu
I've packed a plugin with the fix.
https://www.npmjs.com/package/cordova-plugin-calendar-ios-fix

It should work also on Capacitor due to the fact it has a real small difference with the original plugin but I haven't tested.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants