0

I am trying to get user photos media permissions on IOS but it's giving me unavailable every time it calls the function how can I fix this problem and do things the correct way? I am using react-native-permissions package to do that...

i also added "PhotoLibrary" in my package.json package in "reactNativePermissionsIOS" block also in my Info.plist file i added <key>NSPhotoLibraryUsageDescription</key> <string>This app needs access to your media library to function properly.</string> follow up pod install

import React, { useEffect } from 'react';
import { View, Text, Pressable } from 'react-native';
import { check, request, PERMISSIONS, RESULTS } from 'react-native-permissions';

const App = () => {

  const requestUserMediaPermission = async () => {
    try {
      const status = await check(PERMISSIONS.IOS.PHOTO_LIBRARY);
      if (status === RESULTS.GRANTED) {
        console.log('Permission already granted');
        return;
      }
      request(PERMISSIONS.IOS.PHOTO_LIBRARY).then(result => {
        console.log(result)
      })
    } catch (err) {
      console.log(err)
    }
  }

  return (
    <View style={{ backgroundColor: 'black', flex: 1, justifyContent: 'center' }}>
      <Pressable onPress={() => requestUserMediaPermission()}>
        <Text style={{ fontWeight: 'bold', color: 'white', textAlign: 'center', fontSize: 20 }}>Get Permission</Text>
      </Pressable>
    </View>
  );
};

export default App;
type
  • 23
  • 4

0 Answers0