react-native - 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",
解决方案
推荐阅读
- c# - .NET Core 中的 AppDomainAppId?
- javascript - 如何使用 React Native 调用没有本机模块的本机代码
- python - 我不明白调试解释了什么
- javascript - 在 javascript 中的对象文字内的 IIFE 中使用“this”的问题
- python - 如何将 discord.py remove_roles 用于多个角色?(作为参数的对象列表)
- javascript - ES6 使用 " vs. '
- oracle - 特定日期范围内的汇总日期
- angular - 如何在 Angular 应用程序中构建模型和服务?
- php - 在 Woocommerce 中显示四舍五入的两位小数价格
- eclipse - 将 EMF 表单用于属性窗口