Browse Source

Allow killing/backgrounding the app before finishing setting a passcode

Now, we enforce that passcode is not enabled until we have finished setting a passcode
Samuel Giddins 6 years ago
parent
commit
81e93935e6
2 changed files with 11 additions and 11 deletions
  1. 6 4
      Sources/KeychainCoordinator.swift
  2. 5 7
      Sources/VLCSettingsController.m

+ 6 - 4
Sources/KeychainCoordinator.swift

@@ -144,11 +144,13 @@ class KeychainCoordinator: NSObject, PAPasscodeViewControllerDelegate {
     }
 
     private func passcodeFromKeychain() -> String {
-        if let item = try? XKKeychainGenericPasswordItem(forService: KeychainCoordinator.passcodeService, account: KeychainCoordinator.passcodeService) {
-            return item.secret.stringValue
-        }
-        assert(false, "Couldn't retrieve item from Keychain! If passcodeLockEnabled we should have an item and secret")
+      do {
+        let item = try XKKeychainGenericPasswordItem(forService: KeychainCoordinator.passcodeService, account: KeychainCoordinator.passcodeService)
+        return item.secret.stringValue
+      } catch let error {
+        assert(false, "Couldn't retrieve item from Keychain! If passcodeLockEnabled we should have an item and secret. Error was \(error)")
         return ""
+      }
     }
 
     // MARK: PAPassCodeDelegate

+ 5 - 7
Sources/VLCSettingsController.m

@@ -130,12 +130,11 @@ NSString * const kVLCSectionTableHeaderViewIdentifier = @"VLCSectionTableHeaderV
     if ([notification.object isEqual:kVLCSettingPasscodeOnKey]) {
         BOOL passcodeOn = [[notification.userInfo objectForKey:kVLCSettingPasscodeOnKey] boolValue];
 
+        [self updateForPasscode:nil];
         if (passcodeOn) {
             PAPasscodeViewController *passcodeLockController = [[PAPasscodeViewController alloc] initForAction:PasscodeActionSet];
             passcodeLockController.delegate = self;
-            [self presentViewController:passcodeLockController animated:YES completion:nil];
-        } else {
-            [self updateForPasscode:nil];
+            [self.navigationController presentViewController:passcodeLockController animated:YES completion:nil];
         }
     }
     if ([notification.object isEqual:kVLCSettingAppTheme]) {
@@ -191,10 +190,9 @@ NSString * const kVLCSectionTableHeaderViewIdentifier = @"VLCSectionTableHeaderV
     NSError *error = nil;
     [VLCKeychainCoordinator setPasscodeWithPasscode:passcode error:&error];
     if (error == nil) {
-        if (passcode == nil) {
-            //Set manually the value to NO to disable the UISwitch.
-            [[NSUserDefaults standardUserDefaults] setBool:NO forKey:kVLCSettingPasscodeOnKey];
-        }
+        //Set manually the value to enable/disable the UISwitch.
+        BOOL passcodeEnabled = passcode != nil;
+        [[NSUserDefaults standardUserDefaults] setBool:passcodeEnabled forKey:kVLCSettingPasscodeOnKey];
         [self updateUIAndCoreSpotlightForPasscodeSetting:passcode != nil];
     }
     if ([self.navigationController.presentedViewController isKindOfClass:[PAPasscodeViewController class]]) {