Opening a popup of windows in iOS 13 in Xcode 11.3

After upgrading Xcode to version 11.3, popup windows calling in iOS 13 stopped working because keyWindow is deprecated, the code is

UIViewController *qtController = [[UIApplication sharedApplication].keyWindow rootViewController];  
UIActivityViewController *activityController = [[UIActivityViewController alloc] initWithActivityItems:sharingItems applicationActivities:nil];
[qtController presentViewController:activityController animated:YES completion:nil];
UIPopoverPresentationController *popController = activityController.popoverPresentationController;
if (popController) popController.sourceView = qtController.view;

In the old Xcode, everything worked fine on iOS 13.

Replies

Yes, because now you need to use scene.


First some edit to make your code readable

UIViewController *qtController = [[UIApplication sharedApplication].keyWindow rootViewController];
UIActivityViewController *activityController = [[UIActivityViewController alloc] initWithActivityItems:sharingItems applicationActivities:nil];

[qtController presentViewController:activityController animated:YES completion:nil];
UIPopoverPresentationController *popController = activityController.popoverPresentationController;
if (popController) popController.sourceView = qtController.view;

Look here for one of many solutions to get the ketWindow:

for (UIWindow *window in [UIApplication sharedApplication].windows) {
  if (window.isKeyWindow) {
  // you have the key window
  break;
  }
}

https://stackoverflow.com/questions/57009283/how-get-current-keywindow-equivalent-for-multi-window-scenedelegate-xcode-11