Victor Molina
Victor Molina

Reputation: 2641

React Native - How to listen to permissions changes?

I am implementing a screen in which a permission is required to display the main components.

When the permission is asked to the user, if it is not granted, how can I listen to the user permissions changes in the device settings, in order to render the main components when he goes back to the app (which was in background) and has granted the required permission?

Upvotes: 0

Views: 2790

Answers (1)

Victor Molina
Victor Molina

Reputation: 2641

The solution is tu use AppState

  componentDidMount() {
    AppState.addEventListener('change', this._handleAppStateChange);
  }

  componentWillUnmount() {
    AppState.removeEventListener('change', this._handleAppStateChange);
  }

  _handleAppStateChange = (nextAppState) => {
    //Check permission here
  };

Upvotes: 1

Related Questions