2

目前,我有以下代码。

if localAuthenticationContext.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: &authError) {
        
        localAuthenticationContext.evaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, localizedReason: reasonString) { success, evaluateError in
            
            if success {
                self.performSegue(withIdentifier: "settingChange", sender: self)                    //TODO: User authenticated successfully, take appropriate action

如果触摸 id 已正确验证,则代码执行到另一个视图控制器的 segue,但是当我尝试代码时,我收到此错误:

在此处输入图像描述

我在不使用 TouchID 的情况下尝试了代码,它工作正常,但我不知道为什么它在使用 TouchID 时会产生错误。有人可以帮忙吗?

4

1 回答 1

1

performSegue 操作可能存在问题。所有与 UI 更改相关的操作都必须在主队列中执行。DispatchQueue与主一起使用。

试试这个看看(注意: 我在 Swift 4 中有解决方案):

if success {

  DispatchQueue.main.async(execute: {
     self.performSegue(withIdentifier: "settingChange", sender: self)
  })

}
于 2018-02-13T15:08:27.140 回答