Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function addIOS(event: Event) {
let status = await CalendarEventsIOS.authorizationStatus();
if (status === 'undetermined') {
try {
// TODO(localization)
await OkCancelAlert(
'Add to Calendar',
'To add this event to your calendar, you need to allow access to your calendar.'
);
status = await CalendarEventsIOS.authorizeEventStore();
} catch (error) {
console.log('Canceled: Add to Calendar');
return false;
}
}
if (status !== 'authorized') {
if (status === 'restricted') {
OkAlert('Cannot Access Calendar', 'Could not access calendar.');
return false;
} else if (status === 'denied') {
try {
// TODO(localization)
await OkCancelAlert(
'Cannot Access Calendar',
'Please open Settings to allow Calendar permissions.'
async checkPermission() {
const authStatus = await RNCalendarEvents.authorizationStatus();
if (authStatus === 'undetermined') {
const authResult = await RNCalendarEvents.authorizeEventStore();
if (authResult !== 'authorized') await this.requestPermission();
} else if (authStatus !== 'authorized') {
await this.requestPermission();
}
}
.then(status => {
if (status === 'authorized') {
resolve(true);
} else if (promptForPermission) {
RNCalendarEvents.authorizeEventStore()
.then(result => {
dispatch(setCalendarAuthorization(result));
resolve(result === 'authorized');
})
.catch(reject);
} else {
resolve(false);
}
})
.catch(reject);
async function requestCalendarAccess(): Promise {
let status = null
try {
status = await RNCalendarEvents.authorizeEventStore()
} catch (err) {
return false
}
if (status !== 'authorized') {
return promptSettings()
}
return true
}