【问题标题】:Ask for location permission again after user says no the first time用户第一次拒绝后再次请求位置许可
【发布时间】:2018-09-01 22:41:05
【问题描述】:

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

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

【问题讨论】:

  • 尝试从IntentLauncher启用它
  • @PritishVaidya 我试过 IntentLauncherAndroid.startActivityAsync( IntentLauncherAndroid.ACTION_LOCATION_SOURCE_SETTINGS ); 但这没有用。

标签: android ios react-native mobile expo


【解决方案1】:

你在 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'
    // ...
  }
}

【讨论】:

  • 感谢您的回复。我没有独立的应用程序。我正在与世博会一起发布。
猜你喜欢
  • 2019-12-01
  • 2020-07-20
  • 2018-01-05
  • 2019-07-07
  • 2018-09-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-06
相关资源
最近更新 更多