Skip to content

Commit

Permalink
fixed: BiometryNotEnrolled showing wrong message for FaceID device.
Browse files Browse the repository at this point in the history
  • Loading branch information
rushisangani committed Nov 23, 2019
1 parent 01767a8 commit 085569f
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 12 deletions.
7 changes: 7 additions & 0 deletions .swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion BiometricAuthentication.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|

s.name = "BiometricAuthentication"
s.version = "3.1.1"
s.version = "3.1.2"

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
MARKETING_VERSION = 3.1.2;
PRODUCT_BUNDLE_IDENTIFIER = com.rushi.BiometricAuthentication;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand All @@ -321,6 +322,7 @@
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
MARKETING_VERSION = 3.1.2;
PRODUCT_BUNDLE_IDENTIFIER = com.rushi.BiometricAuthentication;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,21 @@ public enum AuthenticationError: Error {

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

switch self {
case .canceledByUser, .fallback, .canceledBySystem:
return ""
case .passcodeNotSet:
return authentication.faceIDAvailable() ? kSetPasscodeToUseFaceID : kSetPasscodeToUseTouchID
return isFaceIdDevice ? kSetPasscodeToUseFaceID : kSetPasscodeToUseTouchID
case .biometryNotAvailable:
return kBiometryNotAvailableReason
case .biometryNotEnrolled:
return authentication.faceIDAvailable() ? kNoFaceIdentityEnrolled : kNoFingerprintEnrolled
return isFaceIdDevice ? kNoFaceIdentityEnrolled : kNoFingerprintEnrolled
case .biometryLockedout:
return authentication.faceIDAvailable() ? kFaceIdPasscodeAuthenticationReason : kTouchIdPasscodeAuthenticationReason
return isFaceIdDevice ? kFaceIdPasscodeAuthenticationReason : kTouchIdPasscodeAuthenticationReason
default:
return authentication.faceIDAvailable() ? kDefaultFaceIDAuthenticationFailedReason : kDefaultTouchIDAuthenticationFailedReason
return isFaceIdDevice ? kDefaultFaceIDAuthenticationFailedReason : kDefaultTouchIDAuthenticationFailedReason
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -112,16 +112,19 @@ public extension BioMetricAuthenticator {
}
}

/// checks if device supports face id authentication
/// checks if device supports face id and authentication can be done
func faceIDAvailable() -> Bool {
let context = LAContext()
var error: NSError?

let canEvaluate = context.canEvaluatePolicy(LAPolicy.deviceOwnerAuthenticationWithBiometrics, error: &error)
if #available(iOS 11.0, *) {
let context = LAContext()
return (context.canEvaluatePolicy(LAPolicy.deviceOwnerAuthenticationWithBiometrics, error: nil) && context.biometryType == .faceID)
return canEvaluate && context.biometryType == .faceID
}
return false
return canEvaluate
}

/// checks if device supports touch id authentication
/// checks if device supports touch id and authentication can be done
func touchIDAvailable() -> Bool {
let context = LAContext()
var error: NSError?
Expand All @@ -132,6 +135,18 @@ public extension BioMetricAuthenticator {
}
return canEvaluate
}

/// checks if device has faceId
/// this is added to identify if device has faceId or touchId
/// note: this will not check if devices can perform biometric authentication
func isFaceIdDevice() -> Bool {
let context = LAContext()
_ = context.canEvaluatePolicy(LAPolicy.deviceOwnerAuthenticationWithBiometrics, error: nil)
if #available(iOS 11.0, *) {
return context.biometryType == .faceID
}
return false
}
}

// MARK:- Private
Expand Down
2 changes: 1 addition & 1 deletion BiometricAuthentication/BiometricAuthentication/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>3.0</string>
<string>$(MARKETING_VERSION)</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSPrincipalClass</key>
Expand Down

0 comments on commit 085569f

Please sign in to comment.