How to Resolve: 'Keywindow' Was Deprecated in iOS 13.0

How to resolve: 'keyWindow' was deprecated in iOS 13.0

This is my solution:

let keyWindow = UIApplication.shared.connectedScenes
.filter({$0.activationState == .foregroundActive})
.compactMap({$0 as? UIWindowScene})
.first?.windows
.filter({$0.isKeyWindow}).first

Usage e.g.:

keyWindow?.endEditing(true)

'keyWindow' is deprecated: first deprecated in iOS 13.0 in Objective-C

You can use the window through AppDelegate class like..

BarcodeScannerVC * controller = [[BarcodeScannerVC alloc] initWithNibName:@"BarcodeScannerVC" bundle:[NSBundle mainBundle]];

//[self presentViewController:controller animated:YES completion:nil];
UIWindow * currentwindow = [[UIApplication sharedApplication] delegate].window;
[currentwindow.rootViewController presentViewController:controller animated:YES completion:nil];

Here i changed to get currentwindow line only so just change it.

UIWindow * currentwindow = [[UIApplication sharedApplication] delegate].window;

How to resolve: 'keyWindow' was deprecated in iOS 13.0

This is my solution:

let keyWindow = UIApplication.shared.connectedScenes
.filter({$0.activationState == .foregroundActive})
.compactMap({$0 as? UIWindowScene})
.first?.windows
.filter({$0.isKeyWindow}).first

Usage e.g.:

keyWindow?.endEditing(true)


Related Topics



Leave a reply



Submit