世博会图书馆可能遭到未处理的拒绝

时间:2018-05-14 15:11:40

标签: react-native promise expo media-library

我正在尝试通过Expo MediaLibrary SDK

在我的媒体库中提取相册

我正在尝试通过功能Expo.MediaLibrary.getAlbumsAsync()获取所有专辑名称,ID等来获取数组。

import React from 'react';
import {
  ActivityIndicator,
  Button,
  Clipboard,
  Image,
  Share,
  StatusBar,
  StyleSheet,
  Text,
  TouchableOpacity,
  View,
  Alert,
} from 'react-native';
import Expo, { MediaLibrary, Permissions, Constants, ImagePicker, registerRootComponent } from 'expo';

export default class ChoosePhotos extends React.Component {
  state = {
    image: null,
    uploading: false,
  };

  //Get Permission and get Albums list

   async componentDidMount(){
     this.getAlbum();
  }

  getAlbum = async () => {
    const { status } = await Permissions.askAsync(Permissions.CAMERA_ROLL);

    if(status !== 'granted'){
      this.setState({ cameraRollPerm: false });

      Alert.alert(
        '',
        'Please grant permissions to access your media library to continue.',
        [
         /*  {text: 'Ask me later', onPress: () => console.log('Ask me later pressed')},
          {text: 'Cancel', onPress: () => console.log('Cancel Pressed'), style: 'cancel'}, */
          {text: 'OK', onPress: () => console.log('OK Pressed')},
        ],
        { cancelable: false }
      );
    }

    let albumList = await MediaLibrary.getAlbumsAsync()
      .then(albumArray => { console.log(albumArray) })
      .catch(() => { console.log("failed to fetch albums.") });

  }

  render() {
    console.log(this.state.image)
    let { image } = this.state;

    return (
      <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
        <Text
          style={{
            fontSize: 20,
            marginBottom: 20,
            textAlign: 'center',
            marginHorizontal: 15,
          }}>
          Example: Upload ImagePicker result
        </Text>

        <Button
          onPress={this._pickImage}
          title="Pick an image from camera roll"
        />

        <Button onPress={this._takePhoto} title="Take a photo" />

        <StatusBar barStyle="default" />
      </View>
    );
  }

  _takePhoto = async () => {
    let pickerResult = await ImagePicker.launchCameraAsync({
    });

    this.props.navigation.navigate('SizeSelectionScreen', {imageLink: pickerResult.uri});
  };

  _pickImage = async () => {
    let pickerResult = await ImagePicker.launchImageLibraryAsync({
    });
    this.props.navigation.navigate('SizeSelectionScreen', {imageLink: pickerResult.uri});
  }; 
}

我得到了同样的旧Promise拒绝错误,即使我已通过catch正确处理它,如果未正确处理承诺,这是否意味着我没有得到我的媒体库专辑详细信息?

这是错误:

Error screenshot

0 个答案:

没有答案