Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
componentDidMount() {
AppState.addEventListener('change', this.handleAppStateChange);
if (Platform.OS === 'ios') {
NotificationsIOS.checkPermissions().then(currentPermissions => {
this.setState({
notificationsAllowed:
!!currentPermissions.badge || !!currentPermissions.sound || !!currentPermissions.alert,
});
});
} else {
// TODO: Check android permissions
}
}
handleAppStateChange = nextAppState => {
if (this.state.appState.match(/inactive|background/) && nextAppState === 'active') {
if (Platform.OS === 'ios') {
NotificationsIOS.checkPermissions().then(currentPermissions => {
this.setState({
notificationsAllowed:
!!currentPermissions.badge ||
!!currentPermissions.sound ||
!!currentPermissions.alert,
});
});
}
}
this.setState({ appState: nextAppState });
};