diff --git a/ios/src/ImageCropPicker.m b/ios/src/ImageCropPicker.m index 710141068..003782e63 100644 --- a/ios/src/ImageCropPicker.m +++ b/ios/src/ImageCropPicker.m @@ -125,7 +125,35 @@ - (void) setConfiguration:(NSDictionary *)options } - (UIViewController*) getRootVC { - UIViewController *root = [[[[UIApplication sharedApplication] delegate] window] rootViewController]; + UIViewController *root = nil; + if (@available(iOS 13.0, *)) { + for (id scene in [UIApplication sharedApplication].connectedScenes) { + if (![scene isKindOfClass:[UIWindowScene class]]) { + continue; + } + UIWindowScene *windowScene = (UIWindowScene *)scene; + if (windowScene.activationState == UISceneActivationStateForegroundActive) { + if (@available(iOS 15.0, *)) { + root = windowScene.keyWindow.rootViewController; + } else { + for (UIWindow *window in windowScene.windows) { + if ([window isKeyWindow]) { + root = [window rootViewController]; + break; + } + } + } + if (root != nil) { + break; + } + } + } + } + + if (root == nil) { + root = [[[[UIApplication sharedApplication] delegate] window] rootViewController]; + } + while (root.presentedViewController != nil) { root = root.presentedViewController; }