iOS:调用AppDelegate的打开网址时不显示触摸ID [英] iOS : Touch Id is not shown when AppDelegate's open url is invoked

查看:63
本文介绍了iOS:调用AppDelegate的打开网址时不显示触摸ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序支持打开其他应用程序中的文档,例如图像,pdf.Tocuh ID的实现如下所示,当应用程序进入前台时会被请求

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 {

             }
})

现在,当用户从后台打开应用或重新启动应用时,请求触摸ID的工作正常.当从其他应用程序打开该应用程序时会出现问题,例如点击应用程序URL,使用复制到MyApp"选项从外部应用程序共享文档,其中,AppDelegate的打开url方法的调用如下所示

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
}

问题是,当从外部应用程序启动应用程序时,将调用上述打开的url方法,并且还会按预期方式调用 UIApplicationWillEnterForeground 观察程序.但是在该UIApplicationWillEnterForeground观察器中,LAContext().evaluatePolicy突然失败,并出现错误呼叫者移至后台".

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."

请注意,该问题可以在iOS 11.0.3、11.3 上看到,而在iOS 11.4或< 11

Note, issue can be seen on iOS 11.0.3, 11.3 whereas it is not reproducible with iOS 11.4 or <11

推荐答案

当应用为 applicationDidBecomeActive

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")
                }
            }
    })

}

})

这篇关于iOS:调用AppDelegate的打开网址时不显示触摸ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆