diff --git a/pass/Base.lproj/Main.storyboard b/pass/Base.lproj/Main.storyboard index 986ca2c..d393d98 100644 --- a/pass/Base.lproj/Main.storyboard +++ b/pass/Base.lproj/Main.storyboard @@ -640,7 +640,7 @@ - + @@ -684,11 +684,6 @@ - - - - - @@ -697,7 +692,7 @@ - + @@ -807,7 +802,7 @@ - + @@ -1133,11 +1128,11 @@ Phone Support PIN #: 84719 - + - - - - - - - - - - - - - - - - - - @@ -1745,6 +1722,6 @@ Cgo - + diff --git a/pass/Controllers/OTPScannerController.swift b/pass/Controllers/OTPScannerController.swift index f9c71da..680ec70 100644 --- a/pass/Controllers/OTPScannerController.swift +++ b/pass/Controllers/OTPScannerController.swift @@ -11,7 +11,6 @@ import AVFoundation class OTPScannerController: QRScannerController { - var tempPassword: Password? var scannedOTP: String? // MARK: - AVCaptureMetadataOutputObjectsDelegate Methods @@ -27,14 +26,11 @@ class OTPScannerController: QRScannerController { // check whether it is a valid result if let scannedString = metadataObj.stringValue { if let (accept, message) = delegate?.checkScannedOutput(line: scannedString) { + scannerOutput.text = message if accept == true { captureSession?.stopRunning() scannedOTP = scannedString - tempPassword = Password(name: "empty", plainText: scannedString) - // set scannerOutput - setupOneTimePasswordMessage() - } else { - scannerOutput.text = message + presentSaveAlert() } } else { // no delegate, show the scanned result @@ -50,34 +46,28 @@ class OTPScannerController: QRScannerController { } } - private func setupOneTimePasswordMessage() { - if let password = tempPassword { - if password.otpType == .hotp { - // hotp, no need to refresh - let (title, content) = password.getOtpStrings()! - scannerOutput.text = "\(title):\(content)" - } else if password.otpType == .totp { - // totp, refresh - Timer.scheduledTimer(withTimeInterval: 1, repeats: true) { - [weak weakSelf = self] timer in + private func presentSaveAlert() { + // initialize alert + let password = Password(name: "empty", plainText: scannedOTP!) + let (title, content) = password.getOtpStrings()! + let alert = UIAlertController(title: "Success", message: "\(title): \(content)", preferredStyle: UIAlertControllerStyle.alert) + alert.addAction(UIAlertAction(title: "Save", style: UIAlertActionStyle.default, handler: {[unowned self] (action) -> Void in + self.delegate?.handleScannedOutput(line: self.scannedOTP!) + self.navigationController?.popViewController(animated: true) + })) + + if password.otpType == .hotp { + // hotp, no need to refresh + self.present(alert, animated: true, completion: nil) + } else if password.otpType == .totp { + // totp, refresh otp + self.present(alert, animated: true) { + let alertController = self.presentedViewController as! UIAlertController + Timer.scheduledTimer(withTimeInterval: 1, repeats: true) {_ in let (title, content) = password.getOtpStrings()! - weakSelf?.scannerOutput.text = "\(title):\(content)" + alertController.message = "\(title): \(content)" } } } } - - override func shouldPerformSegue(withIdentifier identifier: String, sender: Any?) -> Bool { - if identifier == "saveAddScannedOTPSegue" { - return tempPassword != nil - } - return true - } - -// override func prepare(for segue: UIStoryboardSegue, sender: Any?) { -// super.prepare(for: segue, sender: sender) -// if segue.identifier == "saveAddScannedOTPSegue" { -// delegate?.handleScannedOutput(line: scannedOTP) -// } -// } } diff --git a/pass/Controllers/PasswordEditorTableViewController.swift b/pass/Controllers/PasswordEditorTableViewController.swift index f27f95c..99760c1 100644 --- a/pass/Controllers/PasswordEditorTableViewController.swift +++ b/pass/Controllers/PasswordEditorTableViewController.swift @@ -226,12 +226,4 @@ class PasswordEditorTableViewController: UITableViewController, FillPasswordTabl @IBAction private func cancelOTPScanner(segue: UIStoryboardSegue) { } - - @IBAction func saveScannedOTP(segue: UIStoryboardSegue) { - if let controller = segue.source as? OTPScannerController { - if let scannedOTP = controller.scannedOTP { - insertScannedOTPFields(scannedOTP) - } - } - } }