From f6c888abd4ad1aafbfeaac6d3f49ae6a7fabe24e Mon Sep 17 00:00:00 2001 From: EddyVerbruggen Date: Thu, 14 Jun 2018 19:42:31 +0200 Subject: [PATCH] The plugin may crash your app on iOS with NativeScript 4 #158 --- src/barcodescanner.ios.ts | 19 +++++++------------ src/package-lock.json | 2 +- src/package.json | 2 +- 3 files changed, 9 insertions(+), 14 deletions(-) diff --git a/src/barcodescanner.ios.ts b/src/barcodescanner.ios.ts index 496c443..02d4500 100644 --- a/src/barcodescanner.ios.ts +++ b/src/barcodescanner.ios.ts @@ -1,6 +1,5 @@ import {BarcodeScannerView as BarcodeScannerBaseView, ScanOptions, ScanResult} from "./barcodescanner-common"; import * as utils from "tns-core-modules/utils/utils"; -import * as frame from "tns-core-modules/ui/frame"; export class BarcodeScannerView extends BarcodeScannerBaseView { @@ -157,7 +156,7 @@ export class BarcodeScanner { public stop(): Promise { return new Promise((resolve, reject) => { try { - let app = utils.ios.getter(UIApplication, UIApplication.sharedApplication); + const app = utils.ios.getter(UIApplication, UIApplication.sharedApplication); app.keyWindow.rootViewController.dismissViewControllerAnimatedCompletion(true, null); this._removeVolumeObserver(); this._closeCallback && this._closeCallback(); @@ -241,17 +240,13 @@ export class BarcodeScanner { this._device.unlockForConfiguration(); } - let topMostFrame = frame.topmost(); - if (topMostFrame) { - let vc = topMostFrame.currentPage && topMostFrame.currentPage.ios; - if (vc) { - vc.presentViewControllerAnimatedCompletion(this._scanner, true, () => { - if (arg.torchOn) { - this._enableTorch(); - } - }); + const app = utils.ios.getter(UIApplication, UIApplication.sharedApplication); + app.keyWindow.rootViewController.presentViewControllerAnimatedCompletion(this._scanner, true, () => { + if (arg.torchOn) { + this._enableTorch(); } - } + }); + } catch (ex) { console.log("Error in barcodescanner.scan: " + ex); reject(ex); diff --git a/src/package-lock.json b/src/package-lock.json index b352eb7..bfb0570 100644 --- a/src/package-lock.json +++ b/src/package-lock.json @@ -1,6 +1,6 @@ { "name": "nativescript-barcodescanner", - "version": "2.7.6", + "version": "2.7.7", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/src/package.json b/src/package.json index 4ce32b8..3a29c89 100644 --- a/src/package.json +++ b/src/package.json @@ -1,6 +1,6 @@ { "name": "nativescript-barcodescanner", - "version": "2.7.6", + "version": "2.7.7", "description": "Scan QR/barcodes with your NativeScript app.", "main": "barcodescanner", "typings": "index.d.ts",