0.1.6 • Published 1 year ago

react-native-check-permissions v0.1.6

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

react-native-check-permissions

permissions check of ios and android; Camera、PhotoLibrary、Location、Bluetooth、Microphone are available openSettings is for user to open setting page, and change permissions

Installation

npm install react-native-check-permissions

Usage

import {
  checkMicrophone,
  requestMicrophone,
  checkCamera,
  requestCamera,
  requestPhotoLibrary,
  openLimitedPhotoLibraryPicker,
  openSettings,
  requestMediaLibrary,
  requestCoreLocation,
  requestBluetooth
} from 'react-native-check-permissions';

// ...

<Button title={'设置'} onPress={() => {
  openSettings().then(res => {
    console.log(res);
    // alert(res);
  })
}}/>
<Button title={'麦克风'} onPress={() => {
  requestMicrophone().then(res => {
    this.showResult(res);
  })
}}/>
<Button title={'相机'} onPress={() => {
  requestCamera().then(res => {
    this.showResult(res);
  })
}}/>
<Button title={'相册'} onPress={() => {
  requestPhotoLibrary().then(res => {
    this.showResult(res);
  })
}}/>
<Button title={'打开有限的相册'} onPress={() => {
  openLimitedPhotoLibraryPicker().then(res => {
    this.showResult(res);
  }).catch(e => {
    console.log(e.message);
  })
}}/>
<Button title={'多媒体'} onPress={() => {
  requestMediaLibrary().then(res => {
    this.showResult(res);
  }).catch(e => {
    console.log(e.message);
  })
}}/>
<Button title={'位置'} onPress={() => {
  requestCoreLocation().then(res => {
    this.showResult(res);
  }).catch(e => {
    console.log(e.message);
  })
}}/>
<Button title={'蓝牙'} onPress={() => {
  requestBluetooth().then(res => {
    this.showResult(res);
  }).catch(e => {
    console.log(e.message);
  })
}}/>

//..
showResult = (res: any) => {
  let {status} = res;
  switch (status) {
    case 0:
      // 不可用
      break;
    case 1:
      // 未定
      break;
    case 2:
      // 受限制的
      break;
    case 3:
      // 拒绝
      Alert.alert('提示', '无权限,请打开设置!', [{text: '取消'}, {
        text: '设置', onPress: () => {
          openSettings().then(res => {
          });
        }
      }])
      break;
    case 4:
      // 已认证
      break;
    case 5:
      // 有限的
      break;
    default:
      break;
  }
  this.setState({
    result: status
  })
}

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT


Made with create-react-native-library