Browse Source

VLCKeychainCoordinator: don't reset passcode on update

That led to not showing the screen after initially setting a passcode.
Additionally resetting _avoidPromptingTouchID in completionblock avoids double showing
of the Touch id prompt
Carola Nitz 7 years ago
parent
commit
e7b9cf3e76
2 changed files with 10 additions and 23 deletions
  1. 0 1
      Sources/VLCConstants.h
  2. 10 22
      Sources/VLCKeychainCoordinator.m

+ 0 - 1
Sources/VLCConstants.h

@@ -13,7 +13,6 @@
 
 
 #define kVLCVersionCodename @"All Along the Watchtower"
 #define kVLCVersionCodename @"All Along the Watchtower"
 
 
-#define kVLCSettingPasscodeResetOnUpgrade @"kVLCSettingPasscodeResetOnUpgrade"
 #define kVLCSettingPasscodeOnKey @"PasscodeProtection"
 #define kVLCSettingPasscodeOnKey @"PasscodeProtection"
 #define kVLCSettingPasscodeAllowTouchID @"AllowTouchID"
 #define kVLCSettingPasscodeAllowTouchID @"AllowTouchID"
 #define kVLCAutomaticallyPlayNextItem @"AutomaticallyPlayNextItem"
 #define kVLCAutomaticallyPlayNextItem @"AutomaticallyPlayNextItem"

+ 10 - 22
Sources/VLCKeychainCoordinator.m

@@ -65,20 +65,11 @@ NSString *const VLCPasscode = @"org.videolan.vlc-ios.passcode";
     }
     }
 }
 }
 
 
-- (NSString *)_obtainPasscode
+- (NSString *)passcodeFromKeychain
 {
 {
-    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
-    BOOL wasReset = [defaults boolForKey:kVLCSettingPasscodeResetOnUpgrade];
-    if (wasReset) {
-        XKKeychainGenericPasswordItem *item = [XKKeychainGenericPasswordItem itemForService:VLCPasscode account:VLCPasscode error:nil];
-        NSString *passcode = item.secret.stringValue;
-        return passcode;
-    }
-
-    [XKKeychainGenericPasswordItem removeItemsForService:VLCPasscode error:nil];
-    [defaults setBool:YES forKey:kVLCSettingPasscodeResetOnUpgrade];
-
-    return nil;
+    XKKeychainGenericPasswordItem *item = [XKKeychainGenericPasswordItem itemForService:VLCPasscode account:VLCPasscode error:nil];
+    NSString *passcode = item.secret.stringValue;
+    return passcode;
 }
 }
 
 
 - (BOOL)touchIDEnabled
 - (BOOL)touchIDEnabled
@@ -93,15 +84,9 @@ NSString *const VLCPasscode = @"org.videolan.vlc-ios.passcode";
 
 
 - (void)validatePasscodeWithCompletion:(void(^)(void))completion
 - (void)validatePasscodeWithCompletion:(void(^)(void))completion
 {
 {
-    NSString *passcode = [self _obtainPasscode];
-    if (passcode == nil || [passcode isEqualToString:@""]) {
-        completion();
-        return;
-    }
-
     _passcodeLockController = [[PAPasscodeViewController alloc] initForAction:PasscodeActionEnter];
     _passcodeLockController = [[PAPasscodeViewController alloc] initForAction:PasscodeActionEnter];
     _passcodeLockController.delegate = self;
     _passcodeLockController.delegate = self;
-    _passcodeLockController.passcode = passcode;
+    _passcodeLockController.passcode = [self passcodeFromKeychain];
     _completion = completion;
     _completion = completion;
 
 
     UIViewController *rootViewController = [UIApplication sharedApplication].delegate.window.rootViewController;
     UIViewController *rootViewController = [UIApplication sharedApplication].delegate.window.rootViewController;
@@ -121,7 +106,7 @@ NSString *const VLCPasscode = @"org.videolan.vlc-ios.passcode";
 - (void)_touchIDQuery
 - (void)_touchIDQuery
 {
 {
     //if we just entered background don't show TouchID
     //if we just entered background don't show TouchID
-    if (_avoidPromptingTouchID || [UIApplication sharedApplication].applicationState == UIApplicationStateInactive)
+    if (_avoidPromptingTouchID || [UIApplication sharedApplication].applicationState != UIApplicationStateActive)
         return;
         return;
 
 
     LAContext *myContext = [[LAContext alloc] init];
     LAContext *myContext = [[LAContext alloc] init];
@@ -132,12 +117,15 @@ NSString *const VLCPasscode = @"org.videolan.vlc-ios.passcode";
                             reply:^(BOOL success, NSError *error) {
                             reply:^(BOOL success, NSError *error) {
                                 //if we cancel we don't want to show TouchID again
                                 //if we cancel we don't want to show TouchID again
                                 dispatch_async(dispatch_get_main_queue(), ^{
                                 dispatch_async(dispatch_get_main_queue(), ^{
-                                    _avoidPromptingTouchID = !success;
                                     if (success) {
                                     if (success) {
                                         [[UIApplication sharedApplication].delegate.window.rootViewController dismissViewControllerAnimated:YES completion:^{
                                         [[UIApplication sharedApplication].delegate.window.rootViewController dismissViewControllerAnimated:YES completion:^{
                                             _completion();
                                             _completion();
                                             _completion = nil;
                                             _completion = nil;
+                                            _avoidPromptingTouchID = NO;
                                         }];
                                         }];
+                                    } else {
+                                        //user hit cancel and wants to enter the passcode
+                                        _avoidPromptingTouchID = YES;
                                     }
                                     }
                                 });
                                 });
                             }];
                             }];