From 85b8acc760adf7c1132776a8a4a5d90a612fd23d Mon Sep 17 00:00:00 2001 From: surdu Date: Mon, 17 Sep 2018 16:23:46 +0300 Subject: [PATCH] Fixed camera not opening from modal on iOS --- src/camera-plus.ios.ts | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/camera-plus.ios.ts b/src/camera-plus.ios.ts index 47cc257..b663531 100644 --- a/src/camera-plus.ios.ts +++ b/src/camera-plus.ios.ts @@ -236,7 +236,7 @@ export class MySwifty extends SwiftyCamViewController { } public closePicker() { - rootVC().dismissViewControllerAnimatedCompletion(true, () => { + this.getParentViewController().dismissViewControllerAnimatedCompletion(true, () => { this.pickerDelegate = null; }); } @@ -450,6 +450,15 @@ export class MySwifty extends SwiftyCamViewController { return UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.Camera); } + public getParentViewController() { + var responder: UIResponder = this.view; + do { + responder = responder.nextResponder; + } while (responder && !(NSStringFromClass(responder.class()) === 'UIViewControllerImpl')); + + return responder; + } + public chooseFromLibrary(options?: IChooseOptions): Promise { return new Promise((resolve, reject) => { this._pickerDelegate = null; @@ -493,7 +502,7 @@ export class MySwifty extends SwiftyCamViewController { imagePickerController.modalPresentationStyle = UIModalPresentationStyle.CurrentContext; - rootVC().presentViewControllerAnimatedCompletion(imagePickerController, true, null); + this.getParentViewController().presentViewControllerAnimatedCompletion(imagePickerController, true, null); }); } @@ -733,11 +742,6 @@ export class CameraPlus extends CameraPlusBase { } } -const rootVC = function() { - let appWindow = UIApplication.sharedApplication.keyWindow; - return appWindow.rootViewController; -}; - const createButton = function( target: any, frame: CGRect,