Closed johannessachse closed 7 months ago
Hello and thanks for asking, this module does not handle permissions, as documented in the readme: https://github.com/vonovak/react-native-add-calendar-event?tab=readme-ov-file#permissions Thank you 🙂
Hi, in my case (working on android) the calendar opened but when going back it would crash. This issue was the key, the read permission was necessary for this to work. I'm writing this for future reference and I'd change the example code to something like this:
const addCalendarEvent = () => {
Permissions.requestMultiple(
Platform.select({
ios: [Permissions.PERMISSIONS.IOS.CALENDARS_WRITE_ONLY],
android: [
Permissions.PERMISSIONS.ANDROID.WRITE_CALENDAR,
Permissions.PERMISSIONS.ANDROID.READ_CALENDAR,
],
})
)
.then((result) => {
if (!allPermssionGranted(result)) {
throw new Error(`No permission: ${JSON.stringify(result)}`)
}
return AddCalendarEvent.presentEventCreatingDialog(eventConfig)
})
.then((eventInfo) => {
// handle success - receives an object with `calendarItemIdentifier` and `eventIdentifier` keys, both of type string.
// These are two different identifiers on iOS.
// On Android, where they are both equal and represent the event id, also strings.
// when { action: 'CANCELED' } is returned, the dialog was dismissed
console.warn(JSON.stringify(eventInfo))
})
.catch((error) => {
// handle error such as when user rejected permissions
console.warn(error)
})
}
const allPermssionGranted = (result) => {
return Object.values(result).every((permission) => permission === Permissions.RESULTS.GRANTED);
}
Reproduce:
Possible solutions: