wmcmahan / react-native-calendar-events

📆 React Native Module for iOS and Android Calendar Events
MIT License
906 stars 292 forks source link

unauthorized to access calendar on saveCalendar #336

Closed tatva-hiral closed 3 years ago

tatva-hiral commented 3 years ago

Environment

System: OS: Windows 10 10.0.18363 CPU: (4) ia32 Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz Memory: 892.17 MB / 7.82 GB Binaries: Node: 10.16.0 - C:\Program Files (x86)\nodejs\node.EXE Yarn: 1.22.5 - C:\Program Files (x86)\Yarn\bin\yarn.CMD npm: 6.9.0 - C:\Program Files (x86)\nodejs\npm.CMD npmPackages: react: 16.12.0 => 16.12.0 react-native: 0.61.5 => 0.61.5 npmGlobalPackages: react-native-cli: 2.0.1 react-native-screens: 2.11.0

Steps to Reproduce

const deviceCalendarId = await RNCalendarEvents.saveCalendar({
            title: `Custom - ${user.givenName} ${user.familyName}`,
            name: `custom - ${user.givenName} ${user.familyName}`,
            color: "#00ADB5",
            entityType: "event",
            accessLevel: "read",
            ownerAccount: `${user.givenName} ${user.familyName}`,
            source: {
                name: `custom - ${user.givenName} ${user.familyName}`,
                type: "custom type",
            },
        });
MoOx commented 3 years ago

Did you requested permission first?

tatva-hiral commented 3 years ago

Did you requested permission first?

Yes, I did as below :

Installed the latest version of react-native-calendar-events and run react-native link react-native-calendar-events and added permission in AndroidManifest.xml

<uses-permission android:name="android.permission.READ_CALENDAR" />
<uses-permission tools:node="remove" android:name="android.permission.WRITE_CALENDAR" />

And request permission as below :

export const calendarAccessPermission = async () => {
        const status = await RNCalendarEvents.checkPermissions(true);
    if (status !== "authorized") {
        const requestStatus = await RNCalendarEvents.requestPermissions(true);
        if (requestStatus === "authorized" || requestStatus === "undetermined") {
            return true;
        } else {
            return false;
        }
    }else{
        return true;
    }
};

Please help me to short out this issue. Thanks

mikeslinkman commented 3 years ago

Hi,

Without trying if it would solve this, I think you're issue has to do with the use of the readOnly = true for your checkPermissions and requestPermissions method. Which for Android would only enable you to read calendar data and not to save them. Good luck

Edit:

Also make sure you don't remove the write calendar permission, cos that is what your doing in your first codeblock.

MoOx commented 3 years ago

Yeah it seems you are removing write permissions that is required for saving. I will try to make doc clear about that.

tatva-hiral commented 3 years ago

Yes, I update below line as :

const requestStatus = await RNCalendarEvents.requestPermissions();

And it's working, Thanks

gkasireddy202 commented 8 months ago

const requestStatus = await RNCalendarEvents.requestPermissions(); Getting requestStatus is denied.