gpt4 book ai didi

ios - Swift - 后台线程通过身份验证使应用程序崩溃

转载 作者:行者123 更新时间:2023-11-28 23:21:13 32 4
gpt4 key购买 nike

我正在尝试将面容 ID/触控 ID/代码添加到我的应用程序,但我在终止它时遇到了一些问题:这是我得到的错误(在一次运行和另一次运行之间略有不同,例如标识符的数量发生变化):

Can't end BackgroundTask: no background task exists with identifier 12 (0xc), or it may have already been ended. Break in UIApplicationEndBackgroundTaskError() to debug.

我尝试按照说明进行操作,但我不知道该怎么做。在互联网上我发现这可能是 iOS 13 导致的错误,但我没有任何运行 iOS 12 的设备来测试它。

我的设置中没有任何崩溃日志。

这是导致错误的代码:

import UIKit
import LocalAuthentication

class LoginController: VController {

override func viewDidLoad() {
super.viewDidLoad()

let context = LAContext()
var error: NSError?
let reason = "Identificati"

if context.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: &error) {
context.evaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, localizedReason: reason) { (success, err) in
DispatchQueue.main.async {
if success {
context.invalidate()
let layout = UICollectionViewFlowLayout.init()
let dim = (UIScreen.main.bounds.width / 2) - 12
layout.itemSize = CGSize(width: dim, height: dim)
layout.sectionInset = UIEdgeInsets(top: 6, left: 6, bottom: 6, right: 6)
let vc = UINavigationController(rootViewController: ViewController(collectionViewLayout: layout))
vc.modalPresentationStyle = .fullScreen
self.present(vc, animated: true, completion: nil)
} else {
print(err!.localizedDescription)
}
}
}

} else {
if context.canEvaluatePolicy(.deviceOwnerAuthentication, error: &error) {
context.evaluatePolicy(.deviceOwnerAuthentication, localizedReason: reason) { (success, err) in
DispatchQueue.main.async {
if success {
context.invalidate()
let layout = UICollectionViewFlowLayout.init()
let dim = (UIScreen.main.bounds.width / 2) - 12
layout.itemSize = CGSize(width: dim, height: dim)
layout.sectionInset = UIEdgeInsets(top: 6, left: 6, bottom: 6, right: 6)
let vc = UINavigationController(rootViewController: ViewController(collectionViewLayout: layout))
vc.modalPresentationStyle = .fullScreen
self.present(vc, animated: true, completion: nil)
} else {
print(err!.localizedDescription)
}
}
}

} else {
// Nothing worked
}
}
}

}

最佳答案

调用 invalidate()完成后在您的上下文中运行。

关于ios - Swift - 后台线程通过身份验证使应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59626969/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com