簡體   English   中英

用戶第一次拒絕后,再次請求位置權限

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

我正在查看博覽會的文檔,但似乎他們的示例僅觸發一次對話框,要求一次位置許可。 如果用戶拒絕,我該怎么做才能再次觸發對話框? 我得到的只是在控制台上反復嘗試啟動對話框的過程:

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

您在sdk 29上是否有獨立的應用程序? 如果是的話,您可能想看看Expo GitHub上的這個線程

此版本中有一個錯誤,這是解決方法:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM