我正在尝试使用 Expo Calendar
添加事件,但出现错误。当我调用我的函数 openActionSheet
时,会执行 catch
块并获取带有消息 Alert
的 Error getting device calendars.
。当我安慰错误时,我收到了 undefined is not a function (near '...showActionSheetWithOptions...')
。
我的函数代码是:
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.');
}
}