Skip to content

Commit ac8fd53

Browse files
test: Add biometric prompt to permissions (#3624)
Add a button to trigger biometric prompt for the iOS-Swift test app.
1 parent 0559a8f commit ac8fd53

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

Samples/iOS-Swift/iOS-Swift/Info.plist

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
33
<plist version="1.0">
44
<dict>
5+
6+
<key>NSFaceIDUsageDescription</key>
7+
<string>$(PRODUCT_NAME) Authentication with TouchId or FaceID for testing purposes of the Sentry Cocoa SDK.</string>
58
<key>CFBundleDevelopmentRegion</key>
69
<string>$(DEVELOPMENT_LANGUAGE)</string>
710
<key>CFBundleExecutable</key>

Samples/iOS-Swift/iOS-Swift/ViewControllers/PermissionsViewController.swift

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import CoreLocation
2+
import LocalAuthentication
23
import UIKit
34

45
class PermissionsViewController: UIViewController {
@@ -18,9 +19,16 @@ class PermissionsViewController: UIViewController {
1819
button.addTarget(self, action: #selector(requestLocationPermission), for: .touchUpInside)
1920
return button
2021
}()
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+
}()
2129

2230
private lazy var stackView: UIStackView = {
23-
let stackView = UIStackView(arrangedSubviews: [pushPermissionButton, locationPermissionButton])
31+
let stackView = UIStackView(arrangedSubviews: [pushPermissionButton, locationPermissionButton, biometricButton])
2432
stackView.axis = .vertical
2533
stackView.spacing = 10
2634
stackView.alignment = .center
@@ -71,6 +79,34 @@ class PermissionsViewController: UIViewController {
7179
print(granted)
7280
}
7381
}
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+
}
74110
}
75111

76112
extension PermissionsViewController: CLLocationManagerDelegate {

0 commit comments

Comments
 (0)