【发布时间】:2017-12-04 18:57:03
【问题描述】:
在 iOS 11 上,当应用程序使用主页按钮在后台运行时,与当它打开外部 webview 链接并进入 safari 时,应用程序状态似乎有所不同。
返回我的应用后,我要求用户使用触控 ID 进行验证。如果应用程序使用主页按钮在后台运行并返回,则对LAPolicy.deviceOwnerAuthenticationWithBiometrics 的调用会显示提示并等待用户交互。但是,用户通过应用程序中的链接访问外部网站,并使用状态栏中显示的“返回应用程序”按钮返回应用程序,调用LAPolicy.deviceOwnerAuthenticationWithBiometrics 会立即导致错误而不显示touch ID 提示。
我检查了调用时两种情况下的应用程序状态是应用程序是active。它是在主线程上完成的,它是在 applicationDidBecomeActive 上完成的。
这是我看到的错误:
Error Domain=com.apple.LocalAuthentication Code=-1004 "User interaction is required." UserInfo={NSLocalizedDescription=User interaction is required.}`
对LAPolicy.deviceOwnerAuthenticationWithBiometrics 的行为有任何见解吗?用来调用它的代码是:
let context = LAContext()
context.localizedFallbackTitle = ""
print("--> internalAuthenticateBiometrics background \(UIApplication.shared.applicationState == UIApplicationState.background)")
context.evaluatePolicy(LAPolicy.deviceOwnerAuthenticationWithBiometrics, localizedReason:NSLocalizedString("Place your finger to sign in.",comment: "")) { [weak self] (success, error) in
print("--> internalAuthenticateBiometrics completion success \(success) error \(error)")
}
【问题讨论】: