Ionic 4-相机-运行时错误-Object(...)不是函数

时间:2019-04-23 14:58:38

标签: object ionic-framework camera runtime

我正在创建具有摄像头功能的Ionic应用程序。我为此使用了离子框架Ionic native camera

中的文档

但是当我尝试在Android设备上显示该应用程序并单击“拍照” 按钮时,出现错误。

错误

"Runtime Error Object(…) is not a function"

"TypeError: Object(…) is not a function at Camera.getPicture"

home.ts


import { Component } from '@angular/core';
import { NavController, PopoverController, ViewController } from 'ionic-angular';
import { UserServiceProvider } from './../../providers/user-service/user-service';
import { Camera, CameraOptions, DestinationType, EncodingType, MediaType } from '@ionic-native/camera/ngx';

@Component({
  selector: 'page-home',
  templateUrl: 'home.html',
})
export class HomePage {

  constructor(public navCtrl: NavController, public popoverCtrl: PopoverController, private camera:Camera) {}

  myPhoto:any=''

  takePicture(){
    const options: CameraOptions = {
      quality:100,
      destinationType: this.camera.DestinationType.FILE_URI,
      encodingType: this.camera.EncodingType.JPEG,
      mediaType: this.camera.MediaType.PICTURE
    }

    this.camera.getPicture(options).then((imageData)=>{
      this.myPhoto=(<any>window).Ionic.WebView.convertFileSrc(imageData);
    }, (err) => {
      // Error log
    });
  }

  openMoreSetting(event) {
    let popover = this.popoverCtrl.create(PopoverPage);
    popover.present({
      ev: event
    });
  }
}


@Component({
  template: `
    <ion-list>
      <button ion-item>Menu für Settings</button>
    </ion-list>
  `
})
export class PopoverPage {
  constructor(private userServiceProvider: UserServiceProvider,
    private viewCtrl: ViewController) {
  }

  close() {
    this.viewCtrl.dismiss();
  }
}

1 个答案:

答案 0 :(得分:0)

似乎与上周在一个应用程序中遇到的问题相同。

您最好使用cordova-plugin-camera-preview 而不是用cordova-plugin-camera来操纵离子相机。

您可以按照说明here