Skip to content

Instantly share code, notes, and snippets.

@MutableLoss
Last active June 6, 2018 18:07
Show Gist options
  • Save MutableLoss/9e06e2ac17738a8dc3cbabbe66dc1405 to your computer and use it in GitHub Desktop.
Save MutableLoss/9e06e2ac17738a8dc3cbabbe66dc1405 to your computer and use it in GitHub Desktop.
react-native-calendar-events authorization setup
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));
}
...
@ArthurInTheShell
Copy link

Thanks for writing the tutorial helping me to setup the permission request for Calendar!
I found few things that might need attention.

  1. is 'class ' missed in line3?
  2. will line 11 have curly braces?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment