【发布时间】:2021-06-25 07:29:15
【问题描述】:
我正在尝试在本机反应中获取用户在 expo 中的位置。 enableNetworkproviderAsync() 提示启用该位置的弹出窗口。当用户拒绝分享他们的位置时,我想重新打开弹出窗口。目前,当我导航到我的地图屏幕时,弹出窗口只打开一次,当我点击不共享我的位置时,它不会重新打开。
const [locationReady, setLocationReady] = useState(false);
useEffect(() => {
(async () => {
if (!locationReady) {
try {
const enableLocation = await Location.enableNetworkProviderAsync();
setLocationReady(true);
} catch (e) {
setLocationReady(false);
console.log("locationReady erorr");
}
}
})();
}, [locationReady]);
【问题讨论】:
标签: reactjs react-native asynchronous expo use-effect