如何在React Native中实时检查位置设置
我正在研究一个应用程序,在该应用程序中,我正在检查用户关闭或位于其位置。我正在使用React-Native-Location-Enabler
软件包来检查位置设置,它可以正常工作,但问题是它没有给我更新的状态。例如,如果我从移动移动设备的顶部栏处于位置,那么当我刷新应用程序或关闭并再次打开时,它不会给我带来更新的结果,它给了我更新的结果。我想要更新的结果,如果位置从顶部通知栏关闭。
import LocationEnabler from "react-native-location-enabler";
const {
PRIORITIES: { HIGH_ACCURACY },
addListener,
checkSettings,
requestResolutionSettings,
useLocationSettings,
} = LocationEnabler;
const listener = addListener(({ locationEnabled }) =>
console.log(`Location are ${locationEnabled ? "enabled" : "disabled"}`)
);
// Define configuration
const config = {
priority: HIGH_ACCURACY, // default BALANCED_POWER_ACCURACY
alwaysShow: true, // default false
needBle: false, // default false
};
// Check if location is enabled or not
checkSettings(config);
I am working on an application where I am checking that user is off or on their location. I am using react-native-location-enabler
package to check the location setting, it works fine but the problem is it does not give me an updated state. For example, if I am off location from the top bar of the mobile it does not give me an updated result when I do refresh an app or close and open again it gives me the updated result. I want an updated result if the location is off from the top notification bar.
import LocationEnabler from "react-native-location-enabler";
const {
PRIORITIES: { HIGH_ACCURACY },
addListener,
checkSettings,
requestResolutionSettings,
useLocationSettings,
} = LocationEnabler;
const listener = addListener(({ locationEnabled }) =>
console.log(`Location are ${locationEnabled ? "enabled" : "disabled"}`)
);
// Define configuration
const config = {
priority: HIGH_ACCURACY, // default BALANCED_POWER_ACCURACY
alwaysShow: true, // default false
needBle: false, // default false
};
// Check if location is enabled or not
checkSettings(config);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论