Top most view controller with multiple window scenes in iOS13

1.1k Views Asked by At

I'm conforming my application to use multiple windows on iPadOS with iOS 13, as far as I know I cannot access to UIApplication window directly due to it's deprecation, how can I get the top most view controller?

Until iOS12 I use this working solutions, can you suggest an alternative?

+(UIViewController *)topMostViewController
{
    UIViewController *vc = [[UIApplication sharedApplication].delegate.window rootViewController];
    while(vc.presentedViewController)
    {
        vc = vc.presentedViewController;
    }
    return vc;
}
1

There are 1 best solutions below

1
On

see: How get current keywindow equivalent for multi window SceneDelegate Xcode 11?

deprecated: Have you tried Application.shared.keyWindow?.rootViewController? The keyWindow (or mainWindow if you like) is the important part here.