首页 > 解决方案 > CameraRoll.saveToCameraRoll 不是函数(Expo)

问题描述

我正在尝试将使用 React Native Camera 库拍摄的图像存储到我的 Expo 项目的 Gallery 中。

当用户按下按钮时,会触发以下功能:

download = async (imageRef) => {
  try {
    let result  = await takeSnapshotAsync(imageRef, {
      result: "tmpfile",
      width: 1013,
      height: 644,
      quality: 1,
      format: "png",
    });
    await CameraRoll.saveToCameraRoll(result, "photo");
  } catch (e) {
    alert(e);
    console.log('error:', e);
  }
};

takeSnapshotAsync工作正常并且能够获得有效的 data-uri。但调试器显示以下错误CameraRoll

TypeError: CameraRoll.saveToCameraRoll is not a function. (In 'CameraRoll.saveToCameraRoll(result, "photo")', 'CameraRoll.saveToCameraRoll' is undefined)

以下是全码。

import { captureRef as takeSnapshotAsync } from 'react-native-view-shot'
import * as CameraRoll from "@react-native-community/cameraroll";

class ViewScreenSnapStore {
  download = async (imageRef) => {
    try {
      let result  = await takeSnapshotAsync(imageRef, {
        result: "tmpfile",
        width: 1013,
        height: 644,
        quality: 1,
        format: "png",
      });
      await CameraRoll.saveToCameraRoll(result, "photo");
    } catch (e) {
      alert(e);
      console.log('error:', e);
    }
  };
}

export default new ViewScreenSnapStore();

环境:

    "@react-native-community/cameraroll": "^1.3.0",
    "@react-native-community/datetimepicker": "^2.1.0",
    "expo": "~36.0.0",
    "expo-asset": "~8.0.0",
    "expo-font": "~8.0.0",
    "expo-image-picker": "~8.0.1",
    "expo-localization": "~5.0.1",
    "expo-permissions": "~8.0.0",
    "expo-sharing": "~8.0.0",
    "mobx": "5.6.0",
    "mobx-react": "5.3.6",
    "moment": "^2.24.0",
    "native-base": "^2.13.8",
    "react": "~16.9.0",
    "react-dom": "~16.9.0",
    "react-native": "https://github.com/expo/react-native/archive/sdk-36.0.0.tar.gz",

标签: react-nativeexpocamera-roll

解决方案


推荐阅读