我目前正在开发一款使用 React Native 的应用程序,该应用程序的某些功能需要启用定位服务。我一直在研究是否有一种简单的方法来测试用户是否打开了它们,这样我就可以在没有打开的情况下显示不同的 View 。除了特定于 IOS 或 Android 的结果外,我没有找到任何结果。还有其他人找到解决方案吗?
最佳答案
为android使用“react native android location services dialog box”模块
https://www.npmjs.com/package/react-native-android-location-services-dialog-box
安装
npm install react-native-android-location-services-dialog-box --save
js
import LocationServicesDialogBox from "react-native-android-location-services-dialog-box";
LocationServicesDialogBox.checkLocationServicesIsEnabled({
message: "Use Location ?",
ok: "YES",
cancel: "NO"
}).then(function(success) {
console.log(success); // success => "enabled"
).catch((error) => {
console.log(error.message); // error.message => "disabled"
});
关于android - 使用 native react 检查是否启用了位置服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36776780/