reactjs React Native图像点选器中出错,requestCameraRollPermissionsAsync()

zbdgwd5y  于 2022-11-04  发布在  React
关注(0)|答案(1)|浏览(115)
import React, { useEffect, useState } from 'react';
import * as ImagePicker from 'expo-image-picker'

import Screen from './app/components/Screen';

export default function App() {

  const requestPermission = async () => {
    const { granted } = await ImagePicker.requestCameraRollPermissionsAsync();
    if (!granted)
      alert('Enable permission');
  };
  useEffect(() => {
    requestPermission();
  }, [])

  return (
    <Screen></Screen>
  );
}

我尝试使用“expo-image-picker”来授予用户相机滚动权限。但是当我运行我的项目时,它显示“ImagePicker.requestCameraRollPermissionsAsync()被弃用,而使用ImagePicker.requestMediaLibraryPermissionsAsync()”。而且,我的Android设备上没有显示警告框。有人能解释一下这种情况吗?

m528fe3b

m528fe3b1#

从我的理解,

ImagePicker.requestCameraRollPermissionsAsync()

已过时,因此您应该使用

ImagePicker.requestMediaLibraryPermissionsAsync()

相关问题