CameraPreview Ioni c Cordova error 'plugin_not_installed', но плагин установлен | Angular 8 - PullRequest
0 голосов
/ 09 марта 2020

Я делаю приложение, которому нужно получить фотографии, и отправляю это на сервер. Итак, приложение сделано с Ioni c 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"

Это мой Provides для модуля приложения:

providers: [
    CameraPreview
    ]

НО, когда я запускаю ionic cordova run android и запускаю метод takePhoto ()

я получил это ошибка: enter image description here

я уже попытался удалить, удалить android платформу, но ничего .. ошибка не go прочь

ОБНОВЛЕНИЕ я добавил проверку на платформе, но 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

может быть проблема в этом?

Есть какие-нибудь решения?

Спасибо

1 Ответ

0 голосов
/ 09 марта 2020

Эта проблема часто возникает, потому что платформа еще не готова. Пожалуйста, проверьте, готова ли платформа, прежде чем вызывать любой из ваших плагинов:

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)
      });
  }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...