1

I'm looking for implement IRLDocumentScanner CocoaPods like nativescript plugin. I have correctly installed Pod, and have test if I can access in native code from IRLScannerViewController.

Based on documentation for Object C have tried but have crash on save! myScanner.ios.ts

import { Common } from './myScanner.common';

declare var IRLScannerViewController: any

export class myScanner extends Common {
    constructor() {
        super()

    }

       public createNativeView() {
        const session = new AVCaptureSession();
        session.sessionPreset = AVCaptureSessionPreset1280x720;

        const device = AVCaptureDevice.defaultDeviceWithMediaType(AVMediaTypeVideo);
        const input = AVCaptureDeviceInput.deviceInputWithDeviceError(device);
        if (!input) {
            throw new Error("Error trying to open camera.");
        }
        session.addInput(input);

        session.startRunning();

        const videoLayer = AVCaptureVideoPreviewLayer.layerWithSession(session);

        const camereraView = UIView.alloc().initWithFrame({ origin: { x: 0, y: 0 }, size: { width: 400, height: 600 } });
        camereraView.backgroundColor = UIColor.blueColor;
        videoLayer.frame = camereraView.bounds;
        camereraView.layer.addSublayer(videoLayer);
        this.cameraView = camereraView
        return this.cameraView
    }

    public initNativeView() {
        let delegate = IRLScannerViewControllerDelegate.prototype
        const scanner = IRLScannerViewController.standardCameraViewWithDelegate(delegate)
        scanner.presentViewControllerAnimatedCompletion(scanner, true, null);
    }


    public destroyNativeView() {

    }
}

snakom23
  • 199
  • 3
  • 13
  • You can not set `this.nativeView`, that's automatically done when you return the view in `createNativeView`. Also the nativeView should be type of UIView not UIViewController. If the intension is to not embed IRLScannerViewController within your Page, then you should just have a method which can present the controller. Also you are not creating instance of `IRLScannerViewController`, if you are not sure about syntaxes, [generate typings](https://docs.nativescript.org/plugins/Use-Native-iOS-Libraries#generating-typescript-typings) for IntelliSense support – Manoj Sep 01 '19 at 13:24
  • have updated code, can you you help me? – snakom23 Sep 01 '19 at 19:21
  • What errors you see now? Do you have a repo? – Manoj Sep 01 '19 at 19:29
  • have updated code and have this error: `NativeScript encountered a fatal error: Error: Application tried to present modal view controller on itself. Presenting controller is .` – snakom23 Sep 01 '19 at 20:36
  • Same again, you are not implementing a delegate, and you are suppose to present view controller from key window. Verify your syntax against typings from library. – Manoj Sep 01 '19 at 20:40
  • How I can implement delegate? Have get this from typing about `IRLScannerViewControllerDelegate` : `interface IRLScannerViewControllerDelegate extends NSObjectProtocol { cameraViewCancelRequested?(cameraView: IRLScannerViewController): void; cameraViewWillUpdateTitleLabel?(cameraView: IRLScannerViewController): string; didCancelIRLScannerViewController?(cameraView: IRLScannerViewController): void; pageSnappedFrom(image: UIImage, cameraView: IRLScannerViewController): void; }` – snakom23 Sep 01 '19 at 20:42

0 Answers0