`API MISUSE: nil event store in initialization of EKCalendar instance` for createEventInteractivelyWithOptions
KaiserRuben opened this issue · comments
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.
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.
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
I confirm the issue due to the use of XCode 15. Using XCode 14 seems not to reproduce the issue.
Hello
so what is solution to fix it ?
Thank you for help
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/
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
hello
does anyone have solution to make it working,
our app stop working for ios totally as it not adding calendar event
Thank you
@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.