From 2d742a5e8900d27c6ce724d58cfa5919b3ebbaea Mon Sep 17 00:00:00 2001 From: Lethe <37437842+wn-na@users.noreply.github.com> Date: Mon, 4 Nov 2024 13:18:10 +0900 Subject: [PATCH] chore: keyWindow is deprecated --- ios/CaptureProtection.mm | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/ios/CaptureProtection.mm b/ios/CaptureProtection.mm index f0a3a65..a616287 100644 --- a/ios/CaptureProtection.mm +++ b/ios/CaptureProtection.mm @@ -135,9 +135,13 @@ - (void)createRecordProtectionScreen { UIWindow *window = [[[UIApplication sharedApplication] delegate] window]; UIViewController *captureProtectScreenController = (UIViewController *)[[window viewWithTag:TAG_RECORD_PROTECTION_SCREEN] nextResponder]; if (captureProtectScreenController == nil) { - if(self->protecterViewController == nil) { - [self createRecordProtectionScreenWithText:@"record Detected"]; + if(self->protecterViewController != nil) { + [self->protecterViewController willMoveToParentViewController:nil]; + [self->protecterViewController.view removeFromSuperview]; + [self->protecterViewController removeFromParentViewController]; } + [self createRecordProtectionScreenWithText:@"record Detected"]; + [window.rootViewController addChildViewController:self->protecterViewController]; [window.rootViewController.view addSubview:self->protecterViewController.view]; @@ -207,7 +211,7 @@ - (void)secureBackgroundView: (BOOL)show { viewController.view.window.windowLevel = UIWindowLevelAlert; self->protecterScreenViewController = viewController; viewController.view.backgroundColor = UIColor.whiteColor; - UIWindow *window = [UIApplication sharedApplication].keyWindow; + UIWindow *window = [[UIApplication sharedApplication] delegate].window; [window makeKeyAndVisible]; @@ -232,12 +236,13 @@ - (void)secureScreenshotView: (BOOL)isSecure { self->secureTextField = [[UITextField alloc] init]; self->secureTextField.userInteractionEnabled = false; self->secureTextField.tag = TAG_SCREEN_PROTECTION; - UIWindow *window = [UIApplication sharedApplication].keyWindow; + UIWindow *window = [[UIApplication sharedApplication] delegate].window; [window makeKeyAndVisible]; [window.layer.superlayer addSublayer:self->secureTextField.layer]; [self->secureTextField.layer.sublayers.firstObject addSublayer:window.layer]; + [self->secureTextField.layer.sublayers.lastObject addSublayer:window.layer]; } [self->secureTextField setSecureTextEntry:isSecure]; });