首页 文章

Cordova相机插件在react js组件中不起作用

提问于
浏览
1

我正在使用反应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;

1 回答

  • -1

    1.在浏览器中运行应用程序,然后在反应项目中使用npm run build - -p进行构建,一旦构建完成,请复制您的react项目中的www文件夹

    2.完成以下https://cordova.apache.org/docs/en/latest/guide/cli/

    3.once你在xcode中创建了cordova示例应用程序只需将此相机插件添加到项目中 cordova plugin add cordova-plugin-camera https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-camera/

    • 然后在您的cordova应用程序的暂存文件夹中,请将以下WWW文件夹粘贴到cordova项目中

    5.然后终于在ipod或idevices.it中运行cordova项目将工作 . 它可以帮助你

相关问题