Skip to content

Commit 85b8acc

Browse files
committed
Fixed camera not opening from modal on iOS
1 parent b0021c9 commit 85b8acc

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/camera-plus.ios.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ export class MySwifty extends SwiftyCamViewController {
236236
}
237237

238238
public closePicker() {
239-
rootVC().dismissViewControllerAnimatedCompletion(true, () => {
239+
this.getParentViewController().dismissViewControllerAnimatedCompletion(true, () => {
240240
this.pickerDelegate = null;
241241
});
242242
}
@@ -450,6 +450,15 @@ export class MySwifty extends SwiftyCamViewController {
450450
return UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.Camera);
451451
}
452452

453+
public getParentViewController() {
454+
var responder: UIResponder = this.view;
455+
do {
456+
responder = responder.nextResponder;
457+
} while (responder && !(NSStringFromClass(responder.class()) === 'UIViewControllerImpl'));
458+
459+
return <UIViewController>responder;
460+
}
461+
453462
public chooseFromLibrary(options?: IChooseOptions): Promise<any> {
454463
return new Promise((resolve, reject) => {
455464
this._pickerDelegate = null;
@@ -493,7 +502,7 @@ export class MySwifty extends SwiftyCamViewController {
493502

494503
imagePickerController.modalPresentationStyle = UIModalPresentationStyle.CurrentContext;
495504

496-
rootVC().presentViewControllerAnimatedCompletion(imagePickerController, true, null);
505+
this.getParentViewController().presentViewControllerAnimatedCompletion(imagePickerController, true, null);
497506
});
498507
}
499508

@@ -733,11 +742,6 @@ export class CameraPlus extends CameraPlusBase {
733742
}
734743
}
735744

736-
const rootVC = function() {
737-
let appWindow = UIApplication.sharedApplication.keyWindow;
738-
return appWindow.rootViewController;
739-
};
740-
741745
const createButton = function(
742746
target: any,
743747
frame: CGRect,

0 commit comments

Comments
 (0)