I am trying to add a Face ID/Touch ID/Code to my App, but I'm having some trouble when I terminate it: here's the error I get (with slight variations between one run and another, such as the number of the identifier changing):
Can't end BackgroundTask: no background task exists with identifier 12 (0xc), or it may have already been ended. Break in UIApplicationEndBackgroundTaskError() to debug.
I tried following the instructions, but I couldn't figure out what to do. On the internet I found out that this could be an error caused by iOS 13, but I don't have any device running iOS 12 to test it out.
There isn't any crash log in my settings.
Here's the code causing the error:
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
}
}
}
}