@exodus/react-native-screenshot-detector 1.2.3 → 1.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -13,6 +13,8 @@
|
|
|
13
13
|
id screenshotObserver;
|
|
14
14
|
id screenRecordingObserver;
|
|
15
15
|
BOOL isProtectionEnabled;
|
|
16
|
+
UIWindow *originalKeyWindow;
|
|
17
|
+
CALayer *originalSuperlayer;
|
|
16
18
|
}
|
|
17
19
|
|
|
18
20
|
RCT_EXPORT_MODULE();
|
|
@@ -91,7 +93,6 @@ RCT_EXPORT_METHOD(isScreenRecording:(RCTPromiseResolveBlock)resolve
|
|
|
91
93
|
resolve(@(isRecording));
|
|
92
94
|
}
|
|
93
95
|
|
|
94
|
-
// Clear and explicit method names
|
|
95
96
|
RCT_EXPORT_METHOD(subscribeToScreenshotAndScreenRecording) {
|
|
96
97
|
[self startObserving];
|
|
97
98
|
}
|
|
@@ -102,32 +103,90 @@ RCT_EXPORT_METHOD(unsubscribeFromScreenshotAndScreenRecording) {
|
|
|
102
103
|
|
|
103
104
|
// Screenshot Prevention using Secure Text Field
|
|
104
105
|
- (void)enableTrueScreenshotPrevention {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
self.secureTextField
|
|
108
|
-
|
|
106
|
+
@try {
|
|
107
|
+
// Check if the protection is already fully active
|
|
108
|
+
if (isProtectionEnabled && self.secureTextField != nil &&
|
|
109
|
+
originalKeyWindow != nil && originalSuperlayer != nil) {
|
|
110
|
+
|
|
111
|
+
UIWindow *currentKeyWindow = [self getKeyWindow];
|
|
112
|
+
|
|
113
|
+
// Check if the same keyWindow is already fully protected
|
|
114
|
+
if (originalKeyWindow == currentKeyWindow &&
|
|
115
|
+
self.secureTextField.layer.superlayer == originalSuperlayer) {
|
|
116
|
+
NSLog(@"[RNScreenshotDetector] Screenshot protection fully active, skipping");
|
|
117
|
+
return;
|
|
118
|
+
} else {
|
|
119
|
+
NSLog(@"[RNScreenshotDetector] Protection partially active, need to reset");
|
|
120
|
+
// If only partially set, reset and set again
|
|
121
|
+
[self disableTrueScreenshotPrevention];
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (self.secureTextField == nil) {
|
|
126
|
+
self.secureTextField = [[UITextField alloc] init];
|
|
127
|
+
self.secureTextField.userInteractionEnabled = NO;
|
|
128
|
+
self.secureTextField.secureTextEntry = YES;
|
|
129
|
+
}
|
|
109
130
|
|
|
110
131
|
UIWindow *keyWindow = [self getKeyWindow];
|
|
111
132
|
if (keyWindow != nil) {
|
|
112
|
-
|
|
133
|
+
originalKeyWindow = keyWindow;
|
|
134
|
+
originalSuperlayer = keyWindow.layer.superlayer;
|
|
113
135
|
|
|
114
|
-
|
|
115
|
-
[keyWindow.layer.superlayer addSublayer:self.secureTextField.layer];
|
|
136
|
+
[keyWindow makeKeyAndVisible];
|
|
116
137
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
[
|
|
121
|
-
|
|
138
|
+
if (originalSuperlayer != nil) {
|
|
139
|
+
[originalSuperlayer addSublayer:self.secureTextField.layer];
|
|
140
|
+
|
|
141
|
+
[keyWindow.layer removeFromSuperlayer];
|
|
142
|
+
|
|
143
|
+
NSArray *sublayers = self.secureTextField.layer.sublayers;
|
|
144
|
+
if (sublayers.count > 0) {
|
|
145
|
+
[sublayers.firstObject addSublayer:keyWindow.layer];
|
|
146
|
+
} else {
|
|
147
|
+
[self.secureTextField.layer addSublayer:keyWindow.layer];
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
} else {
|
|
151
|
+
NSLog(@"[RNScreenshotDetector] No keyWindow found, cannot enable protection");
|
|
122
152
|
}
|
|
123
|
-
}
|
|
124
|
-
|
|
153
|
+
} @catch (NSException *exception) {
|
|
154
|
+
NSLog(@"[RNScreenshotDetector] Error in enableTrueScreenshotPrevention: %@", exception);
|
|
125
155
|
}
|
|
126
156
|
}
|
|
127
157
|
|
|
128
158
|
- (void)disableTrueScreenshotPrevention {
|
|
129
|
-
|
|
130
|
-
self.secureTextField
|
|
159
|
+
@try {
|
|
160
|
+
if (self.secureTextField != nil) {
|
|
161
|
+
|
|
162
|
+
self.secureTextField.secureTextEntry = NO;
|
|
163
|
+
|
|
164
|
+
// Safe recovery: check if references are valid
|
|
165
|
+
if (originalKeyWindow != nil && originalSuperlayer != nil) {
|
|
166
|
+
// Check if keyWindow is still valid
|
|
167
|
+
if (originalKeyWindow.superview != nil || originalKeyWindow.layer.superlayer != nil) {
|
|
168
|
+
[originalKeyWindow.layer removeFromSuperlayer];
|
|
169
|
+
[originalSuperlayer addSublayer:originalKeyWindow.layer];
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
[self.secureTextField.layer removeFromSuperlayer];
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// Safe reference cleanup
|
|
176
|
+
originalKeyWindow = nil;
|
|
177
|
+
originalSuperlayer = nil;
|
|
178
|
+
|
|
179
|
+
[self.secureTextField removeFromSuperview];
|
|
180
|
+
self.secureTextField = nil;
|
|
181
|
+
}
|
|
182
|
+
} @catch (NSException *exception) {
|
|
183
|
+
NSLog(@"[RNScreenshotDetector] Error in disableTrueScreenshotPrevention: %@", exception);
|
|
184
|
+
originalKeyWindow = nil;
|
|
185
|
+
originalSuperlayer = nil;
|
|
186
|
+
if (self.secureTextField != nil) {
|
|
187
|
+
[self.secureTextField removeFromSuperview];
|
|
188
|
+
self.secureTextField = nil;
|
|
189
|
+
}
|
|
131
190
|
}
|
|
132
191
|
}
|
|
133
192
|
|