gpt4 book ai didi

react-native - undefined 不是对象(评估 '_expo.Permission.askAsync' )

转载 作者:行者123 更新时间:2023-12-04 14:08:24 24 4
gpt4 key购买 nike

我不知道到底是什么问题,但是当我单击按钮选择在控制台中出错的图像时
这是我的代码

_checkPermissions = async () => {
try {
const { status } = await Permission.askAsync(Permission.CAMERA);
this.setState({ camera: status });
const { statusRoll } = await Permission.askAsync(Permission.CAMERA_ROLL);
this.setState({ cameraRoll: statusRoll });
} catch (err) {
console.log(err);
}
};
findNewImage = async () => {
try {
this._checkPermissions();
let result = await ImagePicker.launchImageLibraryAsync({
mediaTypes: "Images",
allowsEditing: true,
quality: 1
});

if (!result.cancelled) {
this.setState({
image: result.uri
});
} else {
console.log("cancel");
}
} catch (err) {
// console.log(err);
}
};

最佳答案

对我来说,解决它的方法是像这样导入权限和 imagePicker:

import * as Permissions from 'expo-permissions';
import * as ImagePicker from 'expo-image-picker';

而不是这个:
import Permissions from 'expo-permissions';
import ImagePicker from 'expo-image-picker';

这基本上是因为没有默认导出

关于react-native - undefined 不是对象(评估 '_expo.Permission.askAsync' ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56120974/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com