Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get correct root VC when using SceneDelegate on iOS 13+ #1800

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion ios/src/ImageCropPicker.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down