Skip to content

Commit 085569f

Browse files
committed
fixed: BiometryNotEnrolled showing wrong message for FaceID device.
1 parent 01767a8 commit 085569f

File tree

6 files changed

+36
-12
lines changed

6 files changed

+36
-12
lines changed

.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

BiometricAuthentication.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Pod::Spec.new do |s|
22

33
s.name = "BiometricAuthentication"
4-
s.version = "3.1.1"
4+
s.version = "3.1.2"
55

66
s.summary = "Use Apple FaceID or TouchID authentication in your app using BiometricAuthentication."
77

BiometricAuthentication/BiometricAuthentication.xcodeproj/project.pbxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@
298298
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
299299
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
300300
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
301+
MARKETING_VERSION = 3.1.2;
301302
PRODUCT_BUNDLE_IDENTIFIER = com.rushi.BiometricAuthentication;
302303
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
303304
PROVISIONING_PROFILE_SPECIFIER = "";
@@ -321,6 +322,7 @@
321322
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
322323
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
323324
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
325+
MARKETING_VERSION = 3.1.2;
324326
PRODUCT_BUNDLE_IDENTIFIER = com.rushi.BiometricAuthentication;
325327
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
326328
PROVISIONING_PROFILE_SPECIFIER = "";

BiometricAuthentication/BiometricAuthentication/Authentication/AuthenticationErrors.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,21 +57,21 @@ public enum AuthenticationError: Error {
5757

5858
// get error message based on type
5959
public func message() -> String {
60-
let authentication = BioMetricAuthenticator.shared
60+
let isFaceIdDevice = BioMetricAuthenticator.shared.isFaceIdDevice()
6161

6262
switch self {
6363
case .canceledByUser, .fallback, .canceledBySystem:
6464
return ""
6565
case .passcodeNotSet:
66-
return authentication.faceIDAvailable() ? kSetPasscodeToUseFaceID : kSetPasscodeToUseTouchID
66+
return isFaceIdDevice ? kSetPasscodeToUseFaceID : kSetPasscodeToUseTouchID
6767
case .biometryNotAvailable:
6868
return kBiometryNotAvailableReason
6969
case .biometryNotEnrolled:
70-
return authentication.faceIDAvailable() ? kNoFaceIdentityEnrolled : kNoFingerprintEnrolled
70+
return isFaceIdDevice ? kNoFaceIdentityEnrolled : kNoFingerprintEnrolled
7171
case .biometryLockedout:
72-
return authentication.faceIDAvailable() ? kFaceIdPasscodeAuthenticationReason : kTouchIdPasscodeAuthenticationReason
72+
return isFaceIdDevice ? kFaceIdPasscodeAuthenticationReason : kTouchIdPasscodeAuthenticationReason
7373
default:
74-
return authentication.faceIDAvailable() ? kDefaultFaceIDAuthenticationFailedReason : kDefaultTouchIDAuthenticationFailedReason
74+
return isFaceIdDevice ? kDefaultFaceIDAuthenticationFailedReason : kDefaultTouchIDAuthenticationFailedReason
7575
}
7676
}
7777
}

BiometricAuthentication/BiometricAuthentication/Authentication/BioMetricAuthenticator.swift

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,16 +112,19 @@ public extension BioMetricAuthenticator {
112112
}
113113
}
114114

115-
/// checks if device supports face id authentication
115+
/// checks if device supports face id and authentication can be done
116116
func faceIDAvailable() -> Bool {
117+
let context = LAContext()
118+
var error: NSError?
119+
120+
let canEvaluate = context.canEvaluatePolicy(LAPolicy.deviceOwnerAuthenticationWithBiometrics, error: &error)
117121
if #available(iOS 11.0, *) {
118-
let context = LAContext()
119-
return (context.canEvaluatePolicy(LAPolicy.deviceOwnerAuthenticationWithBiometrics, error: nil) && context.biometryType == .faceID)
122+
return canEvaluate && context.biometryType == .faceID
120123
}
121-
return false
124+
return canEvaluate
122125
}
123126

124-
/// checks if device supports touch id authentication
127+
/// checks if device supports touch id and authentication can be done
125128
func touchIDAvailable() -> Bool {
126129
let context = LAContext()
127130
var error: NSError?
@@ -132,6 +135,18 @@ public extension BioMetricAuthenticator {
132135
}
133136
return canEvaluate
134137
}
138+
139+
/// checks if device has faceId
140+
/// this is added to identify if device has faceId or touchId
141+
/// note: this will not check if devices can perform biometric authentication
142+
func isFaceIdDevice() -> Bool {
143+
let context = LAContext()
144+
_ = context.canEvaluatePolicy(LAPolicy.deviceOwnerAuthenticationWithBiometrics, error: nil)
145+
if #available(iOS 11.0, *) {
146+
return context.biometryType == .faceID
147+
}
148+
return false
149+
}
135150
}
136151

137152
// MARK:- Private

BiometricAuthentication/BiometricAuthentication/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<key>CFBundlePackageType</key>
1616
<string>FMWK</string>
1717
<key>CFBundleShortVersionString</key>
18-
<string>3.0</string>
18+
<string>$(MARKETING_VERSION)</string>
1919
<key>CFBundleVersion</key>
2020
<string>$(CURRENT_PROJECT_VERSION)</string>
2121
<key>NSPrincipalClass</key>

0 commit comments

Comments
 (0)