简体   繁体   English

用户第一次拒绝后,再次请求位置权限

[英]Ask for location permission again after user says no the first time

I'm looking at the documentation for expo, but it seems their example only triggers a dialog to ask for location permissions once. 我正在查看博览会的文档,但似乎他们的示例仅触发一次对话框,要求一次位置许可。 What can I do to trigger the dialog again if the user says no? 如果用户拒绝,我该怎么做才能再次触发对话框? All I get is this in the console on repeat attempts to launch the dialog: 我得到的只是在控制台上反复尝试启动对话框的过程:

Possible Unhandled Promise Rejection (id: 0):
Error: Location permission not granted

Here's my code: 这是我的代码:

class PermissionsScreen extends React.Component {
  constructor(props) {
    super(props);
  }

    async getLocationAsync() {
        const { Location, Permissions } = Expo;
        const { status } = await Permissions.askAsync(Permissions.LOCATION);
        if (status === 'granted') {
            return Location.getCurrentPositionAsync({enableHighAccuracy: true});
        } else {
            throw new Error('Location permission not granted');
        }
    }

  render() {
    let s = styles;

    return (
      <View style={s.contain}>
        <Text>I'm going to ask for permissions</Text>
        <TouchableOpacity onPress={() => {
            this.getLocationAsync();
        }}>
          <View style={s.button}>
            <Text style={s.buttonText}>Got it</Text>
          </View>
        </TouchableOpacity>
      </View>
    );
  }
}

Do you have a detached app on sdk 29 ? 您在sdk 29上是否有独立的应用程序? if yes, you might want to take a look at this thread on the Expo GitHub. 如果是的话,您可能想看看Expo GitHub上的这个线程

There's is a bug in this version, and here's the workaround: 此版本中有一个错误,这是解决方法:

in proguard-rules.pro add this proguard-rules.pro添加此

-keepclassmembers class * {
  @expo.core.interfaces.ExpoProp *;
}
-keepclassmembers class * {
  @expo.core.interfaces.ExpoMethod *;
}

-keepclassmembers class * {
  @**.expo.core.interfaces.ExpoProp *;
}
-keepclassmembers class * {
  @**.expo.core.interfaces.ExpoMethod *;
}

Then, in app/build.gradle 然后,在app/build.gradle

buildTypes {
  // ...

  release {
    minifyEnabled true
    proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    // ...
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如果用户第一次拒绝,如何再次请求权限(RunTime) - How to ask permission (RunTime) again if the user deny for the first time Phonegap:如果第一次被拒绝,则再次请求许可 - Phonegap: Ask for permission again if denied first time 我如何区分用户是第一次请求权限还是单击了“不再询问”按钮? - How can I distinguish if the user request the permission for the first time or he clicked on the Never Ask Again button? 应用程序在框架中第一次请求位置许可后立即崩溃 - App crashes right after asking for location permission for the first time in frament 将权限设置为“不再询问”后,Android 6棉花糖黑屏 - Android 6 Marshmallow Black Screen after set Permission to Never Ask Again 用户权限检查仅在安装后第一次生效 - User permission check only works first time after installation 我的应用程序第一次不询问棉花糖的运行时权限吗? - My app Does not ask at the first time for the runtime permission for the marshmallow? 反应本机 android 用户首次登录时询问相机权限 - react native android ask camera permission when user first logs in 无法在颤振上请求位置许可 - Cannot ask for location permission on flutter 离子android要求位置许可 - Ionic android ask for location permission
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM