From 988f62c1642e671b4ce8d7857d0d05e031281c6a Mon Sep 17 00:00:00 2001 From: Jackson Silveira Date: Fri, 23 Feb 2024 16:28:00 -0300 Subject: [PATCH] Suport iOS When creating a screenshot it will result in a black screen, ensuring data security. --- src/ios/PrivacyScreenPlugin.m | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/ios/PrivacyScreenPlugin.m b/src/ios/PrivacyScreenPlugin.m index 67303ee..fb66151 100644 --- a/src/ios/PrivacyScreenPlugin.m +++ b/src/ios/PrivacyScreenPlugin.m @@ -4,6 +4,8 @@ * Copyright (c) 2014 Tommy-Carlos Williams. All rights reserved. * MIT Licensed */ +#import "AppDelegate.h" +#import "MainViewController.h" #import "PrivacyScreenPlugin.h" static UIImageView *imageView; @@ -17,6 +19,9 @@ - (void)pluginInitialize [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onAppWillResignActive:) name:UIApplicationWillResignActiveNotification object:nil]; + + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onAppDidFinishLaunching:) + name:UIApplicationDidFinishLaunchingNotification object:nil]; } - (void)onAppDidBecomeActive:(UIApplication *)application @@ -152,4 +157,31 @@ - (NSString*)getImageName:(UIInterfaceOrientation)currentOrientation delegate:(i return imageName; } +- (void)onAppDidFinishLaunching:(NSNotification *)notification { + [self makeSecure]; +} + +- (void) makeSecure { + UIWindow *window = [[[[UIApplication sharedApplication] delegate] window] rootViewController].view.window; + + UITextField *field = [[UITextField alloc] init]; + + UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, field.frame.size.width, field.frame.size.height)]; + + UIImageView *image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"whiteImage"]]; + image.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height); + + field.secureTextEntry = YES; + + [window addSubview:field]; + [view addSubview:image]; + + [window.layer.superlayer addSublayer:field.layer]; + [[field.layer.sublayers lastObject] addSublayer:window.layer]; + + field.leftView = view; + field.leftViewMode = UITextFieldViewModeAlways; +} + + @end \ No newline at end of file