iOS:AppDelegate';调用的是打开的url
我的应用程序支持从其他应用程序打开图像、PDF等文档。 Tocuh Id的实现如下所示,当应用程序进入前台时会请求它iOS:AppDelegate';调用的是打开的url,ios,swift,touch-id,openurl,lacontext,Ios,Swift,Touch Id,Openurl,Lacontext,我的应用程序支持从其他应用程序打开图像、PDF等文档。 Tocuh Id的实现如下所示,当应用程序进入前台时会请求它 NotificationCenter.default.addObserver(forName: .UIApplicationWillEnterForeground, object: nil, queue: .main) { (notification) in LAContext().evaluatePolicy( .deviceOwnerAuthenticatio
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 {
}
})
现在,当用户从后台打开应用程序或重新启动应用程序时,请求触摸Id可以正常工作。
当从其他应用程序打开应用程序时会出现此问题,例如点击应用程序URL,使用“复制到MyApp”选项从外部应用程序共享文档,其中调用AppDelegate的open URL方法,如下所示
public func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
//validate and save url
return true
}
问题是,当从外部应用程序启动应用程序时,会调用上面的open url方法,并且也会按预期调用UIApplicationWillEnterForeground observer。
但在该UIApplicationWillEnterForeground observer中,LAContext()。evaluatePolicy突然失败,并出现错误“调用者移动到后台”
注意,这个问题可以在iOS11.0.3、11.3上看到,但在iOS 11.4或上无法再现,当应用程序是
applicationIDbecomeactive
NotificationCenter.default.addObserver(forName: .UIApplicationDidBecomeActive, object: nil, queue: .main) { (notification) in
let context = LAContext()
var error: NSError?
if context.canEvaluatePolicy(
LAPolicy.deviceOwnerAuthenticationWithBiometrics,
error: &error) {
// Device can use biometric authentication
context.evaluatePolicy(
LAPolicy.deviceOwnerAuthenticationWithBiometrics,
localizedReason: "Access requires authentication",
reply: {(success, error) in
DispatchQueue.main.async {
if let err = error {
switch err._code {
case LAError.Code.systemCancel.rawValue:
self.notifyUser("Session cancelled",
err: err.localizedDescription)
case LAError.Code.userCancel.rawValue:
self.notifyUser("Please try again",
err: err.localizedDescription)
case LAError.Code.userFallback.rawValue:
self.notifyUser("Authentication",
err: "Password option selected")
// Custom code to obtain password here
default:
self.notifyUser("Authentication failed",
err: err.localizedDescription)
}
} else {
self.notifyUser("Authentication Successful",
err: "You now have full access")
}
}
})
}
})
已尝试UIApplicationIDBECOMEACTIVE,问题是,关闭TouchId请求对话框后会再次调用观察者。问题不在
addObserver
中LAContext()中出现问题。
@Anbu.karthik:我可以知道LAContext()有什么问题吗@RajeshRs-一旦您的应用进入非活动状态,请尝试此操作。LAContext().invalidate()
invalidate您的触摸ID@Anbu.karthik:当LAContext().evaluatePolicy(被称为应用程序)进入UIApplicationWillResignActive状态时,如果我执行LAContext.invalidate(),它将取消当前的touchId请求,因为它调用LAError.SystemCancel