0
我正在構建PhoneGap混合應用程序,其中包含使用cordova攝像頭插件的反應js和react-router。我使用PhoneGap開發人員應用程序在iPhone上測試應用程序。問題在於相機不會顯示在按鈕上。任何幫助將不勝感激。下面是攝像頭組件代碼:運行在瀏覽器中的應用程序,然後採取建立使用NPM運行構建Cordova攝像頭插件無法在反應js組件中工作
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;