我已按照本教程在我的应用程序上设置身份验证。它工作正常,但是当尝试终止应用程序时,我得到以下信息:
* 由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“在从主线程访问布局引擎后,不得从后台线程对其进行修改。” * First throw call stack: (0x18bf22a48 0x18bc49fa4 0x18c3f8f08 0x18c1fa03c 0x19035664c 0x190357a00 0x18f604c5c 0x18f6004c8 0x18f600734 0x18f600a54 0x18f6054dc 0x18f605328 0x18f5e7004 0x18f97b134 0x18f97b838 0x18f990f70 0x18f989d7c 0x18f98b790 0x18f98dc6c 0x18f98e168 0x18f98dbbc 0x18f98de24 0x100c0f4ec 0x100c01780 0x1017917fc 0x101792bd8 0x1017952d4 0x1017a4160 0x1017a4a88 0x18bc3eb48 0x18bc41760) libc++abi.dylib: terminating with uncaught exception NSException (lldb) 类型
我不明白这个错误。
这是我的代码:
func authenticateUser() {
let context = LAContext()
var error: NSError?
if context.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: &error) {
let reason = "Identify yourself!"
context.evaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, localizedReason: reason) { [weak self] success, authError in
DispatchQueue.main.async {
if success {
self?.loginSuccessfull()
} else {
DispatchQueue.main.async {
let ac = UIAlertController(title: "Errore", message: "Riprova", preferredStyle: .alert)
ac.addAction(UIAlertAction(title: "Ok", style: .default, handler: { (action) in
self?.authenticateUser()
return
}))
self?.present(ac, animated: true, completion: nil)
}
}
}
}
} else {
let ac = UIAlertController(title: "Errore", message: "Il tuo device non è configurato per l'autenticazione", preferredStyle: .alert)
ac.addAction(UIAlertAction(title: "Ok", style: .default))
self.present(ac, animated: true, completion: nil)
}
if context.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: &error) {
let reason = "Identify yourself!"
context.evaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, localizedReason: reason) {
[unowned self] success, authenticationError in
DispatchQueue.global().async {
if success {
DispatchQueue.main.async {
self.loginSuccessfull()
}
} else {
let ac = UIAlertController(title: "Authentication failed", message: "Sorry!", preferredStyle: .alert)
ac.addAction(UIAlertAction(title: "OK", style: .default))
self.present(ac, animated: true)
}
}
}
} else {
let ac = UIAlertController(title: "Touch ID not available", message: "Your device is not configured for Touch ID.", preferredStyle: .alert)
ac.addAction(UIAlertAction(title: "OK", style: .default))
present(ac, animated: true)
}
}
如您所见,我只是评估生物特征。再说一遍:这在应用程序的整个“生命周期”中都能完美运行,但是当我终止应用程序时问题就出现了。它只是崩溃并让我进入主屏幕。
设置>隐私...中没有崩溃日志