用户第一次说“不”后再次询问位置许可

问题描述 投票:0回答:1

我正在查看expo的文档,但似乎他们的示例只触发了一次请求位置权限的对话框。如果用户拒绝,我该怎么做才能再次触发对话框?我得到的只是在控制台中重复尝试启动对话框:

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

这是我的代码:

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>
    );
  }
}
android ios react-native mobile expo
1个回答
0
投票

你在sdk 29上有一个独立的应用程序吗?如果是的话,你可能想看看Expo GitHub上的this thread

这个版本中有一个错误,这是解决方法:

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 *;
}

然后,在app/build.gradle

buildTypes {
  // ...

  release {
    minifyEnabled true
    proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    // ...
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.