我正在使用本机反应和此库在相机上截取图像的屏幕截图:https://github.com/gre/react-native-view-shot。
我的项目正在正确编译,我可以点击我的“截屏”按钮,它会返回临时文件路径的uri。
2016-12-17 20:02:50.049 [info][tid:com.facebook.react.JavaScript]
'Image saved to ', '/private/var/mobile/Containers/Data/Application/C46841FC-C985-4396-A8DE-9A8C3CD7A9B8/tmp/ReactNative/C06F2B55-C390-495C-A4C5-63988C1CD374.jpg'
但是,当我尝试将图像保存到相机胶卷时,我收到以下错误:
[info][tid:com.facebook.react.JavaScript]
'error save: ', [TypeError: undefined is not an object (evaluating 'RCTCameraRollManager.saveToCameraRoll')
我的设置看起来像这样:
import React, { Component } from 'react';
import {takeSnapshot} from 'react-native-view-shot';
import {
CameraRoll,
Text,
View
} from 'react-native';
import Camera from 'react-native-camera';
export default class CameraView extends Component {
constructor() {
this.camera = null;
}
setCamera(ref) {
this.camera = ref;
}
capture() {
takeSnapshot(this.camera, {format, quality})
.then(
uri => {
console.log("Image saved to ", file);
CameraRoll.saveToCameraRoll(uri, 'photo');
}
)
.catch(error => console.log('error save: ', error));
}
render() {
return (
<View>
<Camera ref={ref => this.setCamera(ref)}>
<Text onPress={() => this.capture()}>
take screenshot
</Text>
</Camera>
</View>
);
}
当我在浏览器中远程调试js错误时,出现以下错误:
TypeError: Cannot read property 'saveToCameraRoll' of undefined
at Function.saveToCameraRoll (CameraRoll.js:159)
at CameraView.js:71
at tryCallOne (core.js:37)
at core.js:123
at JSTimers.js:100
at Object.callTimer (JSTimersExecution.js:95)
at Object.callImmediatesPass (JSTimersExecution.js:199)
at Object.callImmediates (JSTimersExecution.js:214)
at MessageQueue.js:214
at guard (MessageQueue.js:46)
似乎我已经链接了iOS所需的相应库,但仍然遇到上述错误:
为什么在这种情况下会CameraRoll
未定义?
答案 0 :(得分:0)
我实际上没有正确链接libRCTCameraRoll.a
二进制文件。一旦我这样做,这个错误就停止了。