6

Have a problem with usage of LocalAuthentication and support iOS 7.0

when I'm trying to

import LocalAuthentication

I'm getting crash if target iOS version is less than 8.0.

I tried to mark LocalAuthentication.framework as optional in the build phases and check class availability by calling:

var isTouchIDSupported: Bool {
        if let contextClass: AnyClass = NSClassFromString("LAContext") {
            return LAContext().canEvaluatePolicy(.DeviceOwnerAuthenticationWithBiometrics, error: nil)
        }
        return false
    }

it do not crash if I comment LAContext() string like:

var isTouchIDSupported: Bool {
            if let contextClass: AnyClass = NSClassFromString("LAContext") {
                //return LAContext().canEvaluatePolicy(.DeviceOwnerAuthenticationWithBiometrics, error: nil)
            }
            return false

}

it crashes at the first seconds the app is launches if I accessing the any of LA class (LAContext for instance) in any place of my code. What I'm doing wrong here?

Console log for this crash:

dyld: Symbol not found: _objc_isAuto
  Referenced from: /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation
  Expected in: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.1.sdk/usr/lib/libobjc.A.dylib
 in /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation
iiFreeman
  • 5,165
  • 2
  • 29
  • 42
  • Are you using Swift? Then you probably have to create a bridge header file and import it there. – user965972 Oct 17 '14 at 14:06
  • the selected answer didn't actually solved your question. Can you please post the actual answer containing the solution. I am also suffering from the same problem. – Harshit Gupta Oct 27 '14 at 16:06
  • I had the same problem, and changed "Link Framework Automatically" to NO. It didn't resolve the issue. Are you able to fix it? – David Liu Oct 27 '14 at 18:54

4 Answers4

4

This seems to be a bug in the simulator. Do not choose iPhone 5s (7.1). If you use iPhone 5 (7.1) and mark the LocalAuthentification.framework as Optional it works. (Link Framework Automatically to NO as well)

Same problem for iPad Air (7.1), but you can use the Resizable iPad/iPhone option, which works.

akw
  • 2,090
  • 1
  • 15
  • 21
1

LocalAuthentication.framework is available from iOS 8.0. [ iOS Frameworks ]

To avoid the crash in iOS 7, go to 'Project Targets' -> 'Build Phases' -> 'Link Binary with Libraries' -> set LocalAuthentication.framework's status to 'Optional'

Asif Asif
  • 1,511
  • 14
  • 24
  • done, but it's still crashed. It's not crashes only when I removed LocalAuthentification.framework from build phases/link binary with libraries – iiFreeman Oct 17 '14 at 17:27
  • Since the framework is available from iOS 8 and not backward compatible, you are expected use its methods only for iOS 8. You may, for example, put the method call between this condition to avoid crash in below iOS 8. if([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) { \\LocalAuthentification method calls } – Asif Asif Oct 17 '14 at 17:42
  • The problem was in build settings flag "Link Frameworks Automatically" to use @import statement, since I changes it to NO all started to work properly! – iiFreeman Oct 17 '14 at 17:49
  • @iiFreeman I changed "Link Frameworks Automatically" to NO. It didn't work. Is there any other causes for the issue? – David Liu Oct 27 '14 at 19:08
  • @AsifAsif, you should never be testing for optional features by checking the `systemVersion` as a float (which it's not ... what is "8.0.1" as a float?) and should never be performing comparisons like that on floats in general. See [iiFreeman's answer](http://stackoverflow.com/a/26660119/119114) for the proper way to test for this. – Nate Feb 25 '15 at 10:48
1

First I marked LocalAuthentification.framework as Optional changed "Link Framework Automatically" to NO then simple check before access class in code:

- (BOOL)isTouchIDSupported
{
    if (NSClassFromString(@"LAContext")) {
        return [self.context canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:nil];
    }
    return false;
}

Works fine for me, hope that will help somebody

iiFreeman
  • 5,165
  • 2
  • 29
  • 42
1

Try conditionally importing the LocalAuthentication framework and all associated code with pre-processor directives. You'll then be able to run iOS 7.x simulators and devices through Xcode.

r3c0d3
  • 296
  • 3
  • 11