cordova-plugin-camera
正在开发我的离子应用程序。我是用
cordova plugin add cordova-plugin-camera --save
npm i --save @ionic-native/camera
. 包的node_modules文件夹已填充,插件存在于所有插件文件夹中,我还验证了
cordova plugin list
显示插件。我正在使用以下代码尝试启动相机,但它不起作用:
import { Component } from "@angular/core";
import { Platform } from "ionic-angular";
import { Camera, CameraOptions } from "@ionic-native/camera";
@Component({
selector: "page-camera",
templateUrl: "camera.html"
})
export class CameraPage {
public base64Image: string;
constructor(public camera: Camera, public platform: Platform) {}
takePicture() {
this.platform.ready().then(() => {
this.camera
.getPicture({
destinationType: this.camera.DestinationType.DATA_URL,
targetWidth: 1000,
targetHeight: 1000
})
.then(
imageData => {
// imageData is a base64 encoded string
this.base64Image = "data:image/jpeg;base64," + imageData;
},
err => {
console.log(err);
}
);
});
}
}
takePicture()
我没有启动相机,也没有控制台错误,但在safari中,我得到以下错误:
2018-12-13 11:31:24.183490-0500 MyApp[3844:312133] ERROR: Plugin 'Camera' not found, or is not a CDVPlugin. Check your plugin mapping in config.xml.
2018-12-13 11:31:24.183546-0500 MyApp[3844:312133] -[CDVCommandQueue executePending] [Line 142] FAILED pluginJSON = ["Camera1764610053","Camera","takePicture",[50,0,1,1000,1000,0,0,false,false,false,null,0]]