Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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';

like image 656
imcze Avatar asked Feb 13 '19 15:02

imcze


1 Answers

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/zoontek/react-native-permissions

You can then use the open-settings capability of react-native-permissions to open the settings page https://github.com/zoontek/react-native-permissions#opensettings

This requires require modifying native code, so depending on your Expo setup it may not work.

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).

like image 100
Andrew Avatar answered Nov 15 '22 12:11

Andrew