簡體   English   中英

在iOS 7.1上導入LocalAuthentification.framework崩潰

[英]Import LocalAuthentification.framework crashes on iOS 7.1

使用LocalAuthentication時遇到問題並支持iOS 7.0

當我想要的時候

import LocalAuthentication

如果目標iOS版本低於8.0,我就會崩潰。

我嘗試在構建階段將LocalAuthentication.framework標記為可選 ,並通過調用以下方法檢查類可用性

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

如果我評論LAContext()字符串,它不會崩潰:

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

}

如果我在代碼的任何地方訪問任何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

這似乎是模擬器中的一個錯誤。 不要選擇iPhone 5S(7.1)。 如果你使用iPhone 5(7.1)並將LocalAuthentification.framework標記為Optional它可以工作。 鏈接框架自動也NO

iPad Air(7.1)也存在同樣的問題,但您可以使用可調整大小的iPad / iPhone選項。

LocalAuthentication.framework可從iOS 8.0獲得。 [ iOS框架 ]

為了避免iOS 7中的崩潰,請轉到“項目目標” - >“構建階段” - >“鏈接二進制文件庫” - >將LocalAuthentication.framework的狀態設置為“可選”

首先我將LocalAuthentification.framework標記為Optional,“自動鏈接框架”更改為NO,然后在代碼中訪問類之前進行簡單檢查:

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

對我來說很好,希望能幫到別人

嘗試使用預處理器指令有條件地導入LocalAuthentication框架和所有相關代碼。 然后,您就可以通過Xcode運行iOS 7.x模擬器和設備。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM