1
1
import CoreLocation
2
+ import LocalAuthentication
2
3
import UIKit
3
4
4
5
class PermissionsViewController : UIViewController {
@@ -18,9 +19,16 @@ class PermissionsViewController: UIViewController {
18
19
button. addTarget ( self , action: #selector( requestLocationPermission) , for: . touchUpInside)
19
20
return button
20
21
} ( )
22
+
23
+ private lazy var biometricButton : UIButton = {
24
+ let button = UIButton ( type: . system)
25
+ button. setTitle ( " Request Biometric Permission " , for: . normal)
26
+ button. addTarget ( self , action: #selector( requestBiometricPermission) , for: . touchUpInside)
27
+ return button
28
+ } ( )
21
29
22
30
private lazy var stackView : UIStackView = {
23
- let stackView = UIStackView ( arrangedSubviews: [ pushPermissionButton, locationPermissionButton] )
31
+ let stackView = UIStackView ( arrangedSubviews: [ pushPermissionButton, locationPermissionButton, biometricButton ] )
24
32
stackView. axis = . vertical
25
33
stackView. spacing = 10
26
34
stackView. alignment = . center
@@ -71,6 +79,34 @@ class PermissionsViewController: UIViewController {
71
79
print ( granted)
72
80
}
73
81
}
82
+
83
+ @objc func requestBiometricPermission( ) {
84
+ let context = LAContext ( )
85
+ var error : NSError ?
86
+
87
+ if context. canEvaluatePolicy ( . deviceOwnerAuthenticationWithBiometrics, error: & error) {
88
+ let reason = " Identify yourself! "
89
+
90
+ context. evaluatePolicy ( . deviceOwnerAuthenticationWithBiometrics, localizedReason: reason) { success, _ in
91
+
92
+ DispatchQueue . main. async {
93
+ if success {
94
+ let crumb = Breadcrumb ( )
95
+ crumb. message = " Biometry success "
96
+ SentrySDK . addBreadcrumb ( crumb)
97
+ } else {
98
+ let crumb = Breadcrumb ( )
99
+ crumb. message = " Biometry failure "
100
+ SentrySDK . addBreadcrumb ( crumb)
101
+ }
102
+ }
103
+ }
104
+ } else {
105
+ let ac = UIAlertController ( title: " No biometry " , message: " Couldn't access biometry. " , preferredStyle: . alert)
106
+ ac. addAction ( UIAlertAction ( title: " OK " , style: . default) )
107
+ self . present ( ac, animated: true )
108
+ }
109
+ }
74
110
}
75
111
76
112
extension PermissionsViewController : CLLocationManagerDelegate {
0 commit comments