I'm facing an error when I'm trying to create an event in my calendar. Please let me know the solution. Thanks
Error
[Error: createEventAsync must be called with an id (string) of the target calendar]
Component I just called below function onPress of a Button
async addCalendarEvent(date) {
const startDate = new Date(date);
const setting = new Date(date);
const mergeDate = setting.setHours(setting.getHours() + 2);
const endDate = new Date(mergeDate);
console.log('starting date ==> ', startDate);
console.log('end date ==> ', endDate);
const calendarPermission = await Permissions.askAsync(Permissions.CALENDAR);
if (calendarPermission.status === 'granted') {
const eventId = await Calendar.createEventAsync(Calendar.DEFAULT, {
title: 'Con Fusion Table Reservation',
startDate: startDate,
endDate: endDate,
timeZone: 'Asia/Karachi'
}).then((res) => {
console.log('res ==> ', res)
}).catch(err => console.log('error ==> ', err))
console.log('event ==> ', eventId);
// const eventId = await Calendar.createEventAsync(Calendar.DEFAULT, {
// });
} else {
console.log('permission not granted!')
}
}
Calendar: the DEFAULT constant has been removed. This decision was made because Android API doesn't provide something like default calendar. So if you want to create an event, you need to provide a valid calendar's id. Here is the example code for Creating an event in Calendar:Now asking the user for Permissions and Creating Event:
Now this will pop up an event in the device's Calendar.
P.S.Now you can complete your assignment.