我正在为本机库构建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);
}
}
我获得的唯一控制台日志是“ EEEEEEEEEEEEEE greet 8”和“ EEEEEEEEEEEE done”。 永远不会提出委托中的方法。
这是SDK文档: https://github.com/Jumio/mobile-sdk-ios
我想知道我做错了哪一部分。
谢谢
答案 0 :(得分:1)
您必须通过添加@ObjCClass(...)
注释让运行时知道您正在使用特定的委托。
@ObjCClass(NetverifyViewControllerDelegate)
class NsjumiopluginDelegateImpl extends NSObject implements NetverifyViewControllerDelegate {
.....
}
另一种语法是定义静态ObjCProtocols
数组,
class NsjumiopluginDelegateImpl extends NSObject implements NetverifyViewControllerDelegate {
public static ObjCProtocols = [NetverifyViewControllerDelegate];
.....
}