Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

[LAContext biometryType]: unrecognized selector on iOS 11.0.0

Tags:

ios

swift

I see dozens of crashes in fabric

Fatal Exception: NSInvalidArgumentException
-[LAContext biometryType]: unrecognized selector sent to instance 0x1c066aa00

And it's strange because I do call biometryType on LAContext only for iOS 11+.

The code:

    private static var biometryType: BiometryType? {
        let context = LAContext()

        guard context.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: nil),
            context.evaluatedPolicyDomainState == BiometryManager.savedPolicyDomainState else { return nil }

        if #available(iOS 11.0, *) {
            switch context.biometryType {
            case .typeFaceID: return .typeFaceID
            case .typeTouchID: return .typeTouchID
            case .none: return nil
            }
        }
        return .typeTouchID
    }

enter image description here

Any suggestions?

The only clue I have is that all crashes related to 11.0.0. So maybe Apple added biometryType not in 11.0.0 but a bit later.

Links:

https://developer.apple.com/documentation/localauthentication/lacontext/2867583-biometrytype

http://www.codeprocedures.com/question/nsinvalidargumentexception-unrecognized-selector-sent-to-instance-on-specific-phone-with-ios-11/

like image 737
Arsen Avatar asked Dec 01 '17 07:12

Arsen


2 Answers

This works as well:

if #available(iOS 11.0.1, *) {...}

The iPhone X first release was on 11.0.1

From crash reporting, this definitely works.

like image 105
Daniel Avatar answered Oct 04 '22 02:10

Daniel


As @stonesam92 said, it is probably a bug in ios 11.0.0. The below code safeguards me against the crash.

if #available(iOS 11.0, *), authenticationContext.responds(to: #selector(getter: LAContext.biometryType))
like image 39
dev Avatar answered Oct 04 '22 01:10

dev