-1

This is my simple button action to show a XIB file which is actually a bar code scanner in Objective-C.

 - (IBAction)startCamera:(id)sender {
    BarcodeVC * controller = [[BarcodeVC alloc] initWithNibName:@"BarcodeVC" bundle:[NSBundle mainBundle]];
    
    //[self presentViewController:controller animated:YES completion:nil];
     UIWindow * currentwindow = [[UIApplication sharedApplication] keyWindow];
     [currentwindow.rootViewController presentViewController:controller animated:YES completion:nil];
  }

But unfortunately, a warning comes which is:

keyWindow is deprecated: first deprecated in iOS 13.0

I know that since iOS 13 supports the multiple scenes, but Is there any way to solve this in Objective-C? I have seen Swift versions, but I was unsuccessful with Objective-C.

User1075
  • 819
  • 15
  • 36
  • Have you checked this [Link](https://stackoverflow.com/questions/57134259/how-to-resolve-keywindow-was-deprecated-in-ios-13-0/58447461#58447461)? – Ketan Odedra Mar 02 '20 at 06:23

1 Answers1

7

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;
vipul thummar
  • 342
  • 2
  • 9