diff --git a/src/camera-plus.ios.ts b/src/camera-plus.ios.ts index 0dc9649..df5193b 100644 --- a/src/camera-plus.ios.ts +++ b/src/camera-plus.ios.ts @@ -303,7 +303,7 @@ export class MySwifty extends SwiftyCamViewController { } public closePicker() { - rootVC().dismissViewControllerAnimatedCompletion(true, () => { + this.getParentViewController().dismissViewControllerAnimatedCompletion(true, () => { this.pickerDelegate = null; }); } @@ -572,6 +572,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; @@ -636,7 +645,7 @@ export class MySwifty extends SwiftyCamViewController { imagePickerController.mediaType = mediaType; - rootVC().presentViewControllerAnimatedCompletion(imagePickerController, true, null); + this.getParentViewController().presentViewControllerAnimatedCompletion(imagePickerController, true, null); }); } @@ -932,10 +941,6 @@ export class CameraPlus extends CameraPlusBase { } } -const rootVC = function() { - const appWindow = UIApplication.sharedApplication.keyWindow; - return appWindow.rootViewController; -}; const createButton = function( target: any,