Nativescript core cameraplus with Ml-kit拍照问题

Nativescript core cameraplus with Ml-kit problem taking photos

我正在使用带有 cameraplus 插件和来自 firebase 的 ml-kit 的 NativeScript 核心 OCR。我有这个视图代码:

<Page navigatingTo="onNavigatingTo" xmlns:Cam="@nstudio/nativescript-camera-plus">

    <StackLayout>

        <Cam:CameraPlus 
            id="camPlus"
            height="70%"
            width="70%"     
            showCaptureIcon="false"
            showGalleryIcon="false"
            showToggleIcon="false"       
            showFlashIcon="false"
            confirmPhotos="false" 
            debug="true">
        </Cam:CameraPlus>

    <Button text="test" tap="onCapture" />

    </StackLayout>

</Page>

这是 js :

const HomeViewModel = require("./home-view-model");
const firebase = require("nativescript-plugin-firebase");
const imageSourceModule = require("tns-core-modules/image-source");
const CameraPlus = require("@nstudio/nativescript-camera-plus");

exports.onNavigatingTo = function (args) {
    page = args.object;
    mv = page.bindingContext = new HomeViewModel();
};

exports.onCapture = function() {

    camera = page.getViewById("camPlus");
    camera.takePicture({ saveToGallery: false }) 
        .then(function (imageAsset) {

          const source = new imageSourceModule.ImageSource();
          source.fromAsset(imageAsset).
               then((imageSource) => {
               getTextFromPhoto(imageSource);
          });

          }).catch(function (err) {
               console.log("Error -> " + err.message);
          });

};

我有一个错误:

System.err: TypeError: Cannot read property 'then' of undefined

当我只保留方法时:

camera.takePicture({ saveToGallery: false }) 

能用所以一定是js有问题。这个想法是将该照片与 ml-kit 连接(我必须使用 cameraplus 插件,因为它需要集成而不是像在相机(基本)插件中那样启动相机应用程序

请仔细参考documentationtakePicture方法的return值是void而不是Promise。您必须在 CameraPlus 组件上收听 photoCapturedEvent

更新:

如果您使用的是 NativeScript Core,则必须以编程方式添加侦听器。从 XML 开始可能行不通。