Ask for permission if user have declined access for the first time ReactNative

10,671

This is how permissions work in iOS and there is no way to actually get the app to request the permission again once it has been denied. The only way to get the user to enable the permission is to direct them to the settings for their application and manually switch it on.

I do the following for permissions.

  1. When the user clicks the button for the media library, check the status of the permission.
  2. If the permission hasn't been requested -> request permission
  3. If the permission has been previously requested show an alert and tell the user to go to settings page.
  4. If permission has been approved show media library

I use react-native-permissions to check and request the permissions that I need in iOS. https://github.com/yonahforst/react-native-permissions

I then use react-native-open-settings to open the settings page. https://github.com/lunarmayor/react-native-open-settings

Both of these require modifying native code, so they won't work in Expo

I also use Redux (you may be able to use AsyncStorage) in my application and I track the AppState. So I know when the user has come back to the app from the settings screen so I can perform any appropriate actions in the application (like check the permission again, open the media library, etc).

Share:
10,671
imcze
Author by

imcze

Updated on June 13, 2022

Comments

  • imcze
    imcze almost 2 years

    The problem for my application is when user denies the access to media library for the first time then when he comes back and tries to upload a photo from phone the device doesn't ask again du you want to allow this app to enter in your media library, this problem is only in IOS because in Android i can fix it with this:

    import {PermissionsAndroid} from 'react-native';

  • imcze
    imcze over 5 years
    1.When the user clicks the button for the media library, check the status of the permission -> how to check the status of the permission this library github.com/yonahforst/react-native-permissions doesn't support my react-native version 0.57.8
  • Andrew
    Andrew over 5 years
    I use it in my app which is 0.58.4 and it works.
  • Michael Brenndoerfer
    Michael Brenndoerfer almost 2 years
    github.com/zoontek/react-native-permissions#opensettings can now open settings, too. So there is no need for a second package.