forked from haoict/instagram-no-ads
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSecurityViewController.swift
49 lines (39 loc) · 1.34 KB
/
SecurityViewController.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import UIKit
import LocalAuthentication
@objc public class SecurityViewController: UIViewController {
public override func viewDidLoad() {
super.viewDidLoad()
let blurEffect = UIBlurEffect(style: .dark)
let blurView = UIVisualEffectView(effect: blurEffect)
blurView.frame = view.bounds
view.addSubview(blurView)
let authenticateButton = UIButton(frame: CGRect(x: 20, y: 20, width: 200, height: 60))
authenticateButton.setTitle("Authenticate", for: .normal)
authenticateButton.center = view.center
authenticateButton.addTarget(self, action: #selector(self.authenticateButtonTapped), for: .touchUpInside)
view.addSubview(authenticateButton)
self.authenticate()
}
@objc func authenticateButtonTapped(_ sender: Any) {
self.authenticate()
}
func authenticate() {
let context = LAContext()
var error: NSError?
if context.canEvaluatePolicy(.deviceOwnerAuthentication, error: &error) {
let reason = "Identify yourself!"
context.evaluatePolicy(.deviceOwnerAuthentication, localizedReason: reason) {
[weak self] success, authenticationError in
DispatchQueue.main.async {
if success {
self?.dismiss(animated: true, completion: nil);
} else {
// error
}
}
}
} else {
// no biometry
}
}
}