marinofaggiana 4 years ago
parent
commit
d05dcb1970
2 changed files with 20 additions and 17 deletions
  1. 3 0
      iOSClient/AppDelegate.h
  2. 17 17
      iOSClient/AppDelegate.m

+ 3 - 0
iOSClient/AppDelegate.h

@@ -26,6 +26,7 @@
 #import <PushKit/PushKit.h>
 #import <AVKit/AVKit.h>
 #import <LocalAuthentication/LocalAuthentication.h>
+#import <TOPasscodeViewController/TOPasscodeViewController.h>
 
 #import "Reachability.h"
 #import "CCUtility.h"
@@ -87,6 +88,8 @@
 @property (nonatomic, strong) Reachability *reachability;
 @property BOOL lastReachability;
 
+@property (nonatomic, retain) TOPasscodeViewController *passcodeViewController;
+
 @property (nonatomic, strong) CCMain *activeMain;
 @property (nonatomic, strong) CCMain *homeMain;
 @property (nonatomic, strong) CCFavorites *activeFavorites;

+ 17 - 17
iOSClient/AppDelegate.m

@@ -32,7 +32,6 @@
 #import "NCAutoUpload.h"
 #import "NCPushNotificationEncryption.h"
 #import <QuartzCore/QuartzCore.h>
-#import <TOPasscodeViewController/TOPasscodeViewController.h>
 
 @class NCViewerRichdocument;
 
@@ -178,7 +177,7 @@
     
     // Passcode
     dispatch_async(dispatch_get_main_queue(), ^{
-        [self passcode];
+        [self passcodeWithAutomaticallyPromptForBiometricValidation:true];
     });
     
     return YES;
@@ -206,7 +205,7 @@
         return;
     
     NSLog(@"[LOG] Request Passcode");
-    [self passcode];
+    [self passcodeWithAutomaticallyPromptForBiometricValidation:true];
     
     NSLog(@"[LOG] Request Service Server Nextcloud");
     [[NCService sharedInstance] startRequestServicesServer];
@@ -266,6 +265,7 @@
     NSLog(@"[LOG] Enter in Background");
             
     [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:k_notificationCenter_applicationDidEnterBackground object:nil];
+    [self passcodeWithAutomaticallyPromptForBiometricValidation:false];
     
     if([[UIDevice currentDevice] respondsToSelector:@selector(isMultitaskingSupported)]) {
         
@@ -1686,44 +1686,44 @@
 }
 
 #pragma --------------------------------------------------------------------------------------------
-#pragma mark ===== Passcode Delegate =====
+#pragma mark ===== Passcode + Delegate =====
 #pragma --------------------------------------------------------------------------------------------
 
-- (void)passcode
+- (void)passcodeWithAutomaticallyPromptForBiometricValidation:(BOOL)automaticallyPromptForBiometricValidation
 {
     LAContext *laContext = [LAContext new];
     NSError *error;
     
     if ([[CCUtility getBlockCode] length] == 0 || [self.activeAccount length] == 0 || [CCUtility getOnlyLockDir]) return;
    
-    TOPasscodeViewController *passcodeViewController = [[TOPasscodeViewController alloc] initWithStyle:TOPasscodeViewStyleTranslucentLight passcodeType:TOPasscodeTypeSixDigits];
+    self.passcodeViewController = [[TOPasscodeViewController alloc] initWithStyle:TOPasscodeViewStyleTranslucentLight passcodeType:TOPasscodeTypeSixDigits];
     if (@available(iOS 13.0, *)) {
         if ([[UITraitCollection currentTraitCollection] userInterfaceStyle] == UIUserInterfaceStyleDark) {
-            passcodeViewController.style = TOPasscodeViewStyleTranslucentDark;
+            self.passcodeViewController.style = TOPasscodeViewStyleTranslucentDark;
         }
     }
 
-    passcodeViewController.delegate = self;
-    passcodeViewController.allowCancel = false;
-    passcodeViewController.keypadButtonShowLettering = false;
+    self.passcodeViewController.delegate = self;
+    self.passcodeViewController.allowCancel = false;
+    self.passcodeViewController.keypadButtonShowLettering = false;
     
     if ([laContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&error]) {
         if (error == NULL) {
             if (laContext.biometryType == LABiometryTypeFaceID) {
-                passcodeViewController.biometryType = TOPasscodeBiometryTypeFaceID;
-                passcodeViewController.allowBiometricValidation = true;
-                passcodeViewController.automaticallyPromptForBiometricValidation = true;
+                self.passcodeViewController.biometryType = TOPasscodeBiometryTypeFaceID;
+                self.passcodeViewController.allowBiometricValidation = true;
+                self.passcodeViewController.automaticallyPromptForBiometricValidation = automaticallyPromptForBiometricValidation;
             } else if (laContext.biometryType == LABiometryTypeTouchID) {
-                passcodeViewController.biometryType = TOPasscodeBiometryTypeTouchID;
-                passcodeViewController.allowBiometricValidation = true;
-                passcodeViewController.automaticallyPromptForBiometricValidation = true;
+                self.passcodeViewController.biometryType = TOPasscodeBiometryTypeTouchID;
+                self.passcodeViewController.allowBiometricValidation = true;
+                self.passcodeViewController.automaticallyPromptForBiometricValidation = automaticallyPromptForBiometricValidation;
             } else {
                 NSLog(@"No Biometric support");
             }
         }
     }
     
-    [self.window.rootViewController presentViewController:passcodeViewController animated:YES completion:nil];
+    [self.window.rootViewController presentViewController:self.passcodeViewController animated:YES completion:nil];
 }
 
 - (void)didTapCancelInPasscodeViewController:(TOPasscodeViewController *)passcodeViewController