我目前在我的 iOS 应用程序中使用 expo 相机。
当我尝试像这样保存图像时,应用程序崩溃了。
takePicture = async function() {
this.camera.takePictureAsync().then(data => {
FileSystem.moveAsync({
from: data,
to: `${FileSystem.documentDirectory}photos/Photo_${this.state
.photoId}.jpg`,
}).then(() => {
this.setState({
photoId: this.state.photoId + 1,
});
Vibration.vibrate();
}).catch((err) => {
console.log("Error : " + err);
});
}).catch(error => {
console.log(error);
});
Vibration.vibrate();
console.log("Taking pic");
}
对于您描述的第一个问题,尽管您通过将其保存到相机胶卷通过变通方法解决了它,但我建议您发布编辑后的代码以使问题正确更新。
文件系统问题
解决文件系统错误问题,原始代码应该可以正常工作,但您可以检查:
像这样:
async componentDidMount() {
try {
await FileSystem.makeDirectoryAsync(
`${FileSystem.documentDirectory}photos`,
{
intermediates: true, // creates intermediate directories
}
)
} catch (e) {
console.log(e)
}
}
振动问题
振动问题可能是由 react-native 中的错误引起的,如下所述:https://github.com/facebook/react-native/issues/8955#issuecomment-353373616
作为一种解决方法,您可以在设置状态之前振动,即:
takePicture = async function() {
if (this.camera) {
const picture = await this.camera.takePictureAsync();
const pictureFile = await FileSystem.moveAsync(
{
from: picture.uri,
to: `${
FileSystem.documentDirectory
}photos/Photo_${this.state.photoId}.jpg`
}
).catch(err => console.error(err));
Vibration.vibrate();
console.log("ic taken", this.state.photoId);
return this.setState({
photoId: this.state.photoId + 1
});
}
};
关于javascript - 世博相机拍照崩溃应用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46875578/
欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) | Powered by Discuz! X3.4 |