обратные вызовы делегатов не поднимаются с помощью плагина ios - PullRequest
0 голосов
/ 02 декабря 2018

Я создаю плагин ios для собственной библиотеки.

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

Вот фрагмент кода:

import { Common } from './nsjumioplugin.common';
import * as frameModule from "tns-core-modules/ui/frame/frame";


export class Nsjumioplugin extends Common {
    private cancelWithError;
    private finishInitWithError;
    private finishedScan;

    private netverifyViewController: NetverifyViewController;

    constructor() {
        super();
        this.netverifyViewController = NetverifyViewController.alloc();
    }


    public start(merchantApiToken, merchantApiSecret, customerEmail, cancelWithError, finishInitWithError, finishedScan) {
        this.cancelWithError = cancelWithError;
        this.finishInitWithError = finishInitWithError;
        this.finishedScan = finishedScan;

        console.log("EEEEEEEEEEEE greet 8");

        const that = this;
        const config = NetverifyConfiguration.new();
        config.merchantApiToken = merchantApiToken;
        config.merchantApiSecret = merchantApiSecret;
        config.delegate = NsjumiopluginDelegateImpl.new().initWithCallback((netverifyViewController: NetverifyViewController, documentData: NetverifyDocumentData, scanReference: string) => {
            console.log("EEEEEEEEEEE 4");
            that.rootVC().dismissViewControllerAnimatedCompletion(true, null);
            that.finishedScan(documentData);
        });
        config.customerId = customerEmail;

        try {
            this.netverifyViewController.initWithConfiguration(config);

            this.rootVC().presentViewControllerAnimatedCompletion(
                this.netverifyViewController, false, function completion() {
                console.log('EEEEEEEEEEEE done');
            });
        } catch (e) {
            console.log('EEEEEEEEEEEE EXCEPTION HANDLED:', e);
        }
    }

    rootVC() {
        /*
        const appWindow = UIApplication.sharedApplication.keyWindow;
        return appWindow.rootViewController;
        */

        let frame: typeof frameModule = require("tns-core-modules/ui/frame");

        let topMostFrame = frame.topmost();
        if (topMostFrame) {
           let viewController: UIViewController = topMostFrame.currentPage && topMostFrame.currentPage.ios;
           if (viewController) {
               while (viewController.parentViewController) {
                   // find top-most view controler
                   viewController = viewController.parentViewController;
               }

               while (viewController.presentedViewController) {
                   // find last presented modal
                   viewController = viewController.presentedViewController;
               }

               return viewController;
           }
        }

    }

}


class NsjumiopluginDelegateImpl extends NSObject implements NetverifyViewControllerDelegate {

    static new(): NsjumiopluginDelegateImpl {
      return <NsjumiopluginDelegateImpl>super.new();
    }
    private _callback: (netverifyViewController: NetverifyViewController, documentData: NetverifyDocumentData, scanReference: string) => void;

    public initWithCallback(callback: (netverifyViewController: NetverifyViewController, documentData: NetverifyDocumentData, scanReference: string) => void): NsjumiopluginDelegateImpl {
        this._callback = callback;
        return this;
    }

    netverifyViewControllerDidCancelWithErrorScanReference(netverifyViewController: NetverifyViewController, error: NetverifyError, scanReference: string): void {
        console.log("EEEEEEEEEEE 1");
        this._callback(netverifyViewController, null, scanReference);
    }

    netverifyViewControllerDidFinishInitializingWithError?(netverifyViewController: NetverifyViewController, error: NetverifyError): void {
        console.log("EEEEEEEEEEE 2");
        // this.finishInitWithError();
    }

    netverifyViewControllerDidFinishWithDocumentDataScanReference(netverifyViewController: NetverifyViewController, documentData: NetverifyDocumentData, scanReference: string): void {
        console.log("EEEEEEEEEEE 3");
        console.log("finished successfully with scan reference: %@", scanReference);
        this._callback(netverifyViewController, documentData, scanReference);
    }
  }

Я получаю только консольные журналы "EEEEEEEEEEEE greet 8" и "EEEEEEEEEEEE done".Метод в делегате никогда не вызывается.

Вот документы SDK: https://github.com/Jumio/mobile-sdk-ios

Мне интересно, какую часть я делаю неправильно.

Спасибо

1 Ответ

0 голосов
/ 02 декабря 2018

Вы должны сообщить среде выполнения, что используете определенный делегат, добавив аннотацию @ObjCClass(...).

@ObjCClass(NetverifyViewControllerDelegate)
class NsjumiopluginDelegateImpl extends NSObject implements NetverifyViewControllerDelegate {
 .....
}

Альтернативный синтаксис - определить статический массив ObjCProtocols,

class NsjumiopluginDelegateImpl extends NSObject implements NetverifyViewControllerDelegate {
 public static ObjCProtocols = [NetverifyViewControllerDelegate];
 .....
}
...