[英]Permissions and Location api's from expo are not working
權限和位置 api 的功能不起作用。 例如,每當我嘗試實現屬於權限的 function 時,如下例所示:
const { status } = await Permissions.askAsync(Permissions.LOCATION);
基本上,當我突出顯示時,askAsync function 不會彈出,好像我沒有導入它或者它在 API 中不存在,這令人困惑,因為我安裝了所有內容並正確導入了所有內容。
這是要檢查的整個代碼:
import React, { useEffect, useState } from "react";
import {
Text,
View,
StyleSheet,
ScrollView,
TextInput,
Dimensions,
} from "react-native";
import { LinearGradient } from "expo-linear-gradient";
import { Permissions, Location } from "expo";
import MapView from "react-native-maps";
import { LoadingScreen } from "./LoadingScreen";
export const MainScreen = (props) => {
// State variables for location and error message
const [location, setLocation] = useState({});
//
const getLocation = async () => {
const { status } = await Permissions.askAsync(Permissions.LOCATION);
if (status !== "granted") {
console.log("PERMISSION OT GRANTED");
}
};
setLocation(Location.getCurrentPositionAsync());
console.log(location);
useEffect(() => {
getLocation();
});
// Check for loaded status of the component
const [loaded, setLoaded] = useState(null);
React.useEffect(() => {
setLoaded(true);
});
if (loaded) {
return (
<LinearGradient colors={["#d8e5f5", "#eacfe8"]} style={styles.container}>
<MapView
style={{
flex: 1,
height: Dimensions.get("window").height / 2,
width: Dimensions.get("window").width,
}}
loadingEnabled={true}
region={{
latitude: 37.78825,
longitude: -122.4324,
latitudeDelta: 0.015,
longitudeDelta: 0.0121,
}}
/>
</LinearGradient>
);
}
return <LoadingScreen />;
};
提前致謝。
權限獲取者和請求者被移動到他們的特定模塊而不是 expo 權限 API,因此您需要現在從博覽會位置導入 Location.requestForegroundPermissionsAsync() 而不是權限 ZDB974238714CA8DE634A7ACE1D 代碼和文檔示例可以在此鏈接expo-location documentation with example中找到
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.