Last active
June 6, 2018 18:07
-
-
Save MutableLoss/9e06e2ac17738a8dc3cbabbe66dc1405 to your computer and use it in GitHub Desktop.
react-native-calendar-events authorization setup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import RNCalendarEvents from 'react-native-calendar-events' | |
export default App extends Componemnt { | |
constructor() { | |
super(); | |
this.state = { | |
cal_auth: '' | |
} | |
} | |
componentWillMount () | |
// iOS | |
RNCalendarEvents.authorizationStatus() | |
.then(status => { | |
// if the status was previous accepted, set the authorized status to state | |
this.setState({ cal_auth: status }) | |
if(status === 'undetermined') { | |
// if we made it this far, we need to ask the user for access | |
RNCalendarEvents.authorizeEventStore() | |
.then((out) => { | |
if(out == 'authorized') { | |
// set the new status to the auth state | |
this.setState({ cal_auth: out }) | |
} | |
}) | |
} | |
}) | |
.catch(error => console.warn('Auth Error: ', error)); | |
// Android | |
RNCalendarEvents.authorizeEventStore() | |
.then((out) => { | |
if(out == 'authorized') { | |
// set the new status to the auth state | |
this.setState({ cal_auth: out }) | |
} | |
}) | |
.catch(error => console.warn('Auth Error: ', error)); | |
} | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for writing the tutorial helping me to setup the permission request for Calendar!
I found few things that might need attention.