在iOS 7.1上导入LocalAuthentification.framework崩溃

iiF*_*man 6 ios ios7 touch-id swift xcode6

使用LocalAuthentication时遇到问题并支持iOS 7.0

当我想要的时候

import LocalAuthentication
Run Code Online (Sandbox Code Playgroud)

如果目标iOS版本低于8.0,我就会崩溃.

我尝试在构建阶段将LocalAuthentication.framework标记为可选,并通过调用以下方法检查类可用性:

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

如果我评论LAContext()字符串,它不会崩溃:

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

}

如果我在代码的任何地方访问任何LA类(例如LAContext),它会在应用程序启动的第一秒崩溃.我在这里做错了什么?

此崩溃的控制台日志:

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
Run Code Online (Sandbox Code Playgroud)

Asi*_*sif 1

LocalAuthentication.framework 从 iOS 8.0 开始可用。[ iOS 框架]

为了避免 iOS 7 中的崩溃,请转到“项目目标”->“构建阶段”->“将二进制文件与库链接”-> 将 LocalAuthentication.framework 的状态设置为“可选”