react-native RECEIVE_SMS android权限总是会产生'never_ask_again'

时间:2018-06-02 10:18:51

标签: android react-native react-native-android android-permissions

我正在申请多项权限。除了接收短信之外,所有工作都正常,其中结果总是'never_ask_again'

以下是我正在尝试的代码:

_getPermissions = async () => {
try {
  const resuts = await PermissionsAndroid.requestMultiple([
    PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
    PermissionsAndroid.PERMISSIONS.RECEIVE_SMS,
    PermissionsAndroid.PERMISSIONS.READ_PHONE_STATE
  ]);
  if (
    resuts[PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION] !==
    PermissionsAndroid.RESULTS.GRANTED
  ) {
    alert("Permission not granted. The application may not work properly");
  }
  if (
    resuts[PermissionsAndroid.PERMISSIONS.READ_PHONE_STATE] !==
    PermissionsAndroid.RESULTS.GRANTED
  ) {
    alert("Permission not granted. The application may not work properly");
  }
  if (
    resuts[PermissionsAndroid.PERMISSIONS.RECEIVE_SMS] !==
    PermissionsAndroid.RESULTS.GRANTED
  ) {
    alert("Permission not granted. The application may not work properly");
  }
} catch (err) {
  console.warn(err);
}
};

1 个答案:

答案 0 :(得分:0)

将此行固定为相反的条件:

if (
  resuts[PermissionsAndroid.PERMISSIONS.RECEIVE_SMS] ===
  PermissionsAndroid.RESULTS.DENIED
) {
  Alert.alert("Permission not granted. The application may not work properly");
}