react native with expo-location showing Cannot read property 'requestForegroundPermissionsAsync' of undefined

inkz8wg9  于 2023-03-24  发布在  React
关注(0)|答案(1)|浏览(122)

我尝试在下面的代码中使用expo-location:

import * as Location from "expo-location";
import * as TaskManager from 'expo-task-manager';
React.useEffect(() => {
    const config = async () => {
        let resf = await Location.requestForegroundPermissionsAsync();
        let resb = await Location.requestBackgroundPermissionsAsync();
        if (resf.status != 'granted' && resb.status !== 'granted') {
            console.log('Permission to access location was denied');
        } else {
            console.log('Permission to access location granted');
        }
    };

    config();
}, []);

但得到以下错误:

WARN  Possible Unhandled Promise Rejection (id: 0):
 TypeError: Cannot read property 'requestForegroundPermissionsAsync' of undefined
 TypeError: Cannot read property 'requestForegroundPermissionsAsync' of undefined
at ?anon_0_ (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.fammap&modulesOnly=false&runModule=true:119292:75)
at next (native)
at asyncGeneratorStep (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.fammap&modulesOnly=false&runModule=true:20670:26)
at _next (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.fammap&modulesOnly=false&runModule=true:20689:29)
at anonymous

请指出我做错了什么
我已经在Android xml文件中添加了所有权限

goucqfw6

goucqfw61#

我也经历过同样的问题。在我的情况下,问题是,我没有为使用博览会模块正确地准备我的项目。
严格按照世博会安装程序Install Expo Modules为我解决了这个问题。

相关问题