9

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/

12
  • Which devices do generate this crash? Have you verified that it's devices capable of biometric data? I'm wondering wether that guard statement is not working as it should
    – Lefteris
    Dec 1, 2017 at 8:07
  • It crashes on all kind devices except iPhone X but it's mostly iPhone 7.
    – Arsen
    Dec 1, 2017 at 8:23
  • Ok, obviously you are right about the guard statement. Is it working fine with iPhone 7 when you test it ?
    – Lefteris
    Dec 1, 2017 at 8:31
  • @Lefteris yes, it woks on my iPhone 7 and even on iPhone X.
    – Arsen
    Dec 1, 2017 at 8:32
  • Is it possible that an error is occurring but you're not seeing it because you pass nil in for the error parameter in LAContext.canEvaluatePolicy? Dec 3, 2017 at 23:31

4 Answers 4

15
+50

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))
3
  • I did file a bug report with Apple. Awaiting their response :P Dec 8, 2017 at 21:42
  • Could you reproduce the issue in the iOS 11.0 simulator from Xcode 9.0? Or only on devices running iOS 11.0?
    – Adam Johns
    Jan 31, 2018 at 18:11
  • @AdamJohns when attempting to download "iOS 11.0 Simulator" from Xcode components, it would actually install iOS 11.0.1 where this issue is resolved.
    – Antlip Dev
    Mar 23, 2018 at 0:18
11

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.

3

It's not much of a solution, but this appears to be a bug in iOS 11.0.

I've seen multiple reports of this crash and all have been resolved when the user upgraded to a more recent version of iOS.

2

This code works for Objective-C(on iOS 11.0 & below versions)

if (@available(iOS 11.0, *) && [context    respondsToSelector:@selector(biometryType)])
            {}

credits to @Sonu VR

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.