My App supports opening documents like images, pdfs from other apps. Tocuh Id is implemented as shown below, it is requested when app comes to foreground
NotificationCenter.default.addObserver(forName: .UIApplicationWillEnterForeground, object: nil, queue: .main) { (notification) in
LAContext().evaluatePolicy( .deviceOwnerAuthenticationWithBiometrics, localizedReason: "Request Touch ID", reply: { [unowned self] (success, error) -> Void in
if (success) {
} else {
}
})
Now requesting for Touch Id works fine when user opens the app from Background or relaunches. The issue occurs when the app is opened from other app like tapping on app URL, sharing documents from external app using "Copy to MyApp" option, where the AppDelegate's open url method is called as shown below
public func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
//validate and save url
return true
}
The issue is when the app is launched from external app, the above open url method is invoked and also the UIApplicationWillEnterForeground observer is also called as expected. But in that UIApplicationWillEnterForeground observer, LAContext().evaluatePolicy fails abruptly with an error "Caller moved to background."
Note, issue can be seen on iOS 11.0.3, 11.3 whereas it is not reproducible with iOS 11.4 or <11