-2

这是我显示 XIB 文件的简单按钮操作,该文件实际上是 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];
  }

但不幸的是,出现了一个警告:

keyWindow已弃用:首先在 iOS 13.0 中弃用

我知道由于iOS 13支持多个场景,但是在 Objective-C 中有没有办法解决这个问题?我看过 Swift 版本,但我在 Objective-C 上没有成功。

4

1 回答 1

5

您可以通过 AppDelegate 类使用窗口,例如..

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];

在这里,我更改为仅获取当前窗口行,因此只需更改它即可。

UIWindow * currentwindow = [[UIApplication sharedApplication] delegate].window;
于 2020-03-02T07:26:55.610 回答