【问题标题】:CameraPreview Ionic Cordova error 'plugin_not_installed', but the plugin IS installed | Angular 8CameraPreview Ionic Cordova 错误“plugin_not_installed”,但插件已安装 |角 8
【发布时间】:2020-03-09 15:36:24
【问题描述】:

我正在制作一个需要获取照片并将其最后发送到服务器的应用程序。 因此,该应用程序是使用 Ionic 5 和 Angular 8 制作的。

我已经安装了这个插件CameraPreview,这是我的 PhotoComponent:

      constructor(
    private cameraPreview: CameraPreview
    ) { }

  takePhoto() {
    // camera options (Size and location). In the following example, the preview uses the rear camera and display the preview in the back of the webview
    const cameraPreviewOpts: CameraPreviewOptions = {
      x: 0,
      y: 0,
      width: window.screen.width,
      height: window.screen.height,
      camera: 'rear',
      tapPhoto: true,
      previewDrag: true,
      toBack: true,
      alpha: 1
    }

    // start camera
    this.cameraPreview.startCamera(cameraPreviewOpts).then(
      (res) => {
        console.log(res)
      },
      (err) => {
        console.log(err)
      });
    }

}

所以,这是我的 HTML 组件

...
<button mat-raised-button color="primary" (click)="takePhoto()">prendi la foto</button>
...

我已经安装了这样的相机预览插件:

ionic cordova plugin add cordova-plugin-camera-preview
npm install @ionic-native/camera-preview

运行 cordova plugin list 我看到了这个:

cordova-plugin-camera-preview 0.11.2 "cordova-plugin-camera-preview"

这是我在应用模块上提供的:

providers: [
    CameraPreview
    ]

但是,当我运行 ionic cordova run android 并运行方法 takePhoto()

我收到了这个错误:

我已经尝试卸载,删除android平台但没有..错误并没有消失

更新 我在平台上添加了检查,但 Chrome 金丝雀打印我:

Angular is running in the development mode. Call enableProdMode() to enable the production mode.
cordova.js:1233 deviceready has not fired after 5 seconds.
cordova.js:1226 Channel not fired: onCordovaInfoReady

也许是这个问题?

有什么解决办法吗?

谢谢

【问题讨论】:

    标签: android angular cordova ionic-framework


    【解决方案1】:

    这个问题经常发生,因为平台还没有准备好。在调用任何插件之前,请考虑检查平台是否准备就绪:

    import { Component, OnInit } from '@angular/core';
    
    import { Platform } from '@ionic/angular';
    import { CameraPreview, CameraPreviewOptions } from '@ionic-native/camera-preview/ngx'; // don't add ngx if you are on 'ionic-angular' mode
    
    @Component({
      selector: 'app-root',
      templateUrl: 'app.component.html',
      styleUrls: ['app.component.scss']
    })
    export class AppComponent implements OnInit {
      constructor(
        private platform: Platform,
        private cameraPreview: CameraPreview
      ) {
    
      }
    
      ngOnInit() {
        this.platform.ready().then(_ => {
          this.takePhoto() // here the call of your function
        })
      }
    
      takePhoto() {
        const cameraPreviewOpts: CameraPreviewOptions = {
          x: 0,
          y: 0,
          width: window.screen.width,
          height: window.screen.height,
          camera: 'rear',
          tapPhoto: true,
          previewDrag: true,
          toBack: true,
          alpha: 1
        }
    
        // start camera
        this.cameraPreview.startCamera(cameraPreviewOpts).then(
          (res) => {
            console.log(res)
          },
          (err) => {
            console.log(err)
          });
      }
    }
    

    【讨论】:

    • 感谢您的回复。我已经尝试过,现在 chrome canary 打印我在问题的更新部分中输入的消息。
    • @Mr.Developer 这 3 行是信息,不应阻止应用程序功能正常工作,您现在可以忽略它们。之后插件还能用吗?
    • 对不起,插件在强制后无法工作。我仍在寻找其他解决方案。谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-01-14
    • 2019-05-14
    • 1970-01-01
    • 2016-02-15
    • 2020-02-08
    • 2021-04-11
    • 1970-01-01
    相关资源
    最近更新 更多