我正在使用反应js和使用cordova相机插件的react-router构建PhoneGap混合应用程序。我正在使用PhoneGap开发者应用程序测试iPhone上的应用程序。问题是按钮单击时没有显示相机。任何帮助将不胜感激。这是Camera组件代码:
import React from 'react';
import '../css/poc-form.css';
import '../css/POCButton.css';
class Camera extends React.Component {
constructor(props) {
super(props);
this.state = {
value: '' };
this.takePicture = this.takePicture.bind(this);
}
takePicture(event) {
alert('take a picture');
navigator.camera.getPicture(onSuccess, onFail, {
quality: 50,
destinationType: Camera.DestinationType.DATA_URL,
sourceType: Camera.SourceType.CAMERA
});
function onSuccess(imageData) {
var image = document.getElementById('myImage');
image.src = "data:image/jpeg;base64," + imageData;
}
function onFail(message) {
alert('Failed because: ' + message);
}
event.preventDefault();
}
render() {
return (
<div>
<link rel="stylesheet" type="text/css" href="poc.css"/>
<h1>Client ID Scanner</h1>
<button id = "takePicture" className = "POCButton" onClick={this.takePicture} >Take Picture</button>
<img id = "myImage" ></img>
</div>
);
}
}
export default Camera;
答案 0 :(得分:-1)
1.在浏览器中运行应用程序,然后使用npm run build - -p在react项目中进行构建,一旦构建完成,请复制您的react项目中的www文件夹
2.完成以下内容 https://cordova.apache.org/docs/en/latest/guide/cli/
3.你在xcode中创建了cordova示例应用程序,只需将此相机插件添加到项目中即可 cordova插件添加cordova-plugin-camera https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-camera/
5.然后最后在ipod或idevices.it中运行cordova项目将工作。它帮助你