问题
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
回答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'
回答2:
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.
回答3:
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
回答4:
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.
来源:https://stackoverflow.com/questions/26426461/import-localauthentification-framework-crashes-on-ios-7-1