I'm trying to add an event using Expo Calendar but i'm getting an error. When i call my function openActionSheet the catch block is executed and getting the Alert with the message Error getting device calendars.. When i'm consoling the error i'm getting undefined is not a function (near '...showActionSheetWithOptions...').
My function's code is :
async openActionSheet() {
const { status } = await Permissions.askAsync(Permissions.CALENDAR, Permissions.REMINDERS);
if (status === 'granted') {
Calendar.getCalendarsAsync(Calendar.EntityTypes.EVENT)
.then(calendars => calendars.filter(cal => cal.allowsModifications))
.then((calendars) => {
const { showActionSheetWithOptions, navigation } = this.props;
const options = calendars.map(cal => (Platform.OS === 'ios' ? cal.title : cal.source.name)).concat(['Cancel']);
const cancelButtonIndex = calendars.length;
showActionSheetWithOptions({
title: 'Select a calendar:',
options,
cancelButtonIndex,
},
(buttonIndex) => {
const orderId = navigation.getParam('orderId');
const { orderSet } = navigation.getParam('orderSet');
const eventConfig = {
title: `OrderId: ${orderId}` || 'UNKNOWN_NAME',
startDate: new Date(navigation.getParam('orderDate')),
endDate: new Date(navigation.getParam('orderDate')),
location: `${orderSet.location}` || 'UNKNOWN_LOCATION',
notes: '',
};
if (buttonIndex !== cancelButtonIndex) {
Calendar.createEventAsync(calendars[buttonIndex].id, eventConfig)
.then(() => Alert.alert('Success', 'Event has been added to your calendar.'))
.catch(() => {
Alert.alert('Error', 'Event was not saved.');
});
}
});
})
.catch((e) => {
console.log('ERROR');
console.log(e);
Alert.alert('Error', 'Error getting device calendars.');
});
} else {
Alert.alert('Error', 'You have to authorize the application to access your calendar.');
}
}