iOS 14.2 Custom Window auto become keyWindow when touching.

In 14.1 and earlier versions, clicking the custom window will not automatically become the keywindow. Why does 14.2, touching the custom window, it will become the keywindow?

Code Block language
@interface DebugWindow : UIWindow
@end
@implementation DebugWindow
- (void)makeKeyWindow
{
  [super makeKeyWindow];
  NSLog(@"%s", FUNCTION);
}
- (void)resignKeyWindow
{
  [super resignKeyWindow];
  NSLog(@"%s", FUNCTION);
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
  [super touchesBegan:touches withEvent:event];
  NSLog(@"%s", FUNCTION);
}
@end
@interface ViewController ()
@property (nonatomic, strong) DebugWindow *window;
@end
@implementation ViewController
- (void)viewDidLoad {
  [super viewDidLoad];
  DebugWindow *window = [[DebugWindow alloc] initWithFrame:self.view.bounds];
  window.windowScene = [UIApplication sharedApplication].keyWindow.windowScene;
  window.backgroundColor = UIColor.redColor;
  window.center = self.view.center;
  window.hidden = NO;
  self.window = window;
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
  [super touchesBegan:touches withEvent:event];
  NSLog(@"%s", FUNCTION);
}
@end


Why? In 14.1 and earlier versions, clicking the custom window will not automatically become the keywindow. Why does 14.2, touching the custom window, it will become the keywindow?
We also noticed that this behavior changed from 14.2.

We also found this problem.

I had encountered the same problem.

After some time researched and I found out the reason.

Apple had changed the private function [_UIRemoteKeyboards peekApplicationEvent:] 's implementation of UIKit in iOS14.2.

the touch event of custom window will call [_UIRemoteKeyboards peekApplicationEvent:] function.

in previous version [_UIRemoteKeyboards peekApplicationEvent:] did't call [UIWindow _makeKeyWindowIgnoringOldKeyWindow:] to change the keyWindow.

but in iOS 14.2 [_UIRemoteKeyboards peekApplicationEvent:] did.

so it's the reason why the keyWindow change when you touch the custom Window.

iOS 14.2 Custom Window auto become keyWindow when touching.
 
 
Q