bsm-project/Friendvatars/NoteBiometricViewController.swift
2018-11-19 23:41:12 +01:00

70 lines
2.0 KiB
Swift

//
// NoteBiometricViewController.swift
// Friendvatars
//
// Created by Dawid Kubicki on 19/11/2018.
// Copyright © 2018 Razeware. All rights reserved.
//
import UIKit
import KeychainAccess
class NoteBiometricViewController: UIViewController {
@IBAction func isSignOut(_ sender: Any) {
try? AuthController.signOut()
}
@IBOutlet weak var txtSecret: UITextField!
@IBOutlet weak var imgBio: UIImageView!
@IBOutlet weak var lblSecret: UILabel!
let keychain = Keychain(service: "com.dawidkubicki.Friendvatars")
override func viewDidLoad() {
super.viewDidLoad()
if(biometricType == .touchID) {
imgBio.image = UIImage(named: "TouchID")
} else if(biometricType == .faceID) {
imgBio.image = UIImage(named: "FaceID")
} else if(biometricType == .none) {
print("Nie ma możliwości użycia biometrycznego uwierzytelniania")
}
}
@IBAction func storeSecret(_ sender: Any) {
DispatchQueue.global().async {
do {
try self.keychain
.accessibility(.whenPasscodeSetThisDeviceOnly, authenticationPolicy: .userPresence)
.set(self.txtSecret.text!, key: "secret")
} catch let error {
print(error)
}
}
}
@IBAction func getSecret(_ sender: Any) {
DispatchQueue.global().async {
do {
let secret = try self.keychain
.authenticationPrompt("Zaloguj się biometrycznie, aby zobaczyć notatkę")
.get("secret")
self.lblSecret.text = "Twoja ukryta notatka to: \(secret!)"
} catch let error {
print(error)
}
}
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destination.
// Pass the selected object to the new view controller.
}
*/
}