javascript - 深夜被問題困擾求解惑,rn的API之PermissionsAndroidd的問題
大家讲道理
大家讲道理 2017-06-28 09:22:43
0
1
652
/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 * @flow
 */

import React, { Component } from 'react';
import {
  AppRegistry,
  StyleSheet,
  Text,
  View,
  PermissionsAndroid,
  Platform
} from 'react-native';


async function requestCameraPermission() {
  try {
    const granted = await PermissionsAndroid.request(
      PermissionsAndroid.PERMISSIONS.CAMERA,
      {
        'title': 'Cool Photo App Camera Permission',
        'message': 'Cool Photo App needs access to your camera ' +
                   'so you can take awesome pictures.'
      }
    )
    if (granted === PermissionsAndroid.RESULTS.GRANTED) {
      console.log("You can use the camera")
    } else {
      console.log("Camera permission denied")
    }
  } catch (err) {
    console.warn(err)
  }
}
requestCameraPermission()

if(Platform.Version === 23){
  console.log('Running on Lollipop!');
}

export default class myproject2 extends Component {
  render() {
    return (
      <View style={styles.container}>
        <Text style={styles.welcome}>
          Welcome to React Native!
        </Text>
        <Text style={styles.instructions}>
          To get started, edit index.android.js
        </Text>
        <Text style={styles.instructions}>
          Double tap R on your keyboard to reload,{'\n'}
          Shake or press menu button for dev menu
        </Text>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
  welcome: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
  },
  instructions: {
    textAlign: 'center',
    color: '#333333',
    marginBottom: 5,
  },
});

AppRegistry.registerComponent('myproject2', () => myproject2);

問題是這樣的,我想取得某個權限,看過官網的API也查了一些資料我在AndroidManifest.xml裡面是配置過的,手機和模擬器都是安卓6.0的,SDK的版本是23都是沒有問題,但是我在測試的時候就發現,當我呼叫了,他是直接回傳true的,顯示的是You can use the camera,在瀏覽器的控制台裡,但是APP裡沒有任何反應這是為什麼呢?我非常的困擾。我非常的不解,我想問下,大家是這麼寫的,還是說還要配置其他的什麼嗎?

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

全部回覆(1)
漂亮男人

好像是自動賦予權限的,你再設定裡面把權限去掉再看呢

熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!