在我的 iOS 应用程序上,我使用从后台返回后进行生物识别身份验证的典型方法:
@main
struct MyApp: App {
@Environment(\.scenePhase) var phase
var body: some Scene {
WindowGroup {
MainView()
.onChange(of: phase) { (newPhase) in
switch newPhase {
case .active:
biometricsAuthentication()
case .inactive: print("App is inactive")
case .background: print("App is on background")
appBlocked = true
default: print("default")
}
}
}
}
这样做一切正常,但在身份验证方法触发之前,MainView 有一段时间可见,我猜想是因为应用程序从 .background 返回后处于 .inactive 状态的时间很短。
在 MacOS 应用程序版本上,我在 AppDelegate 上将此身份验证方法称为“applicationDidFinishLaunching”方法,并且在身份验证完成之前不会显示任何内容。因此,我尝试使用专用的 AppDelegate 在 iOS 上模拟这一点,并尝试了一些方法,但没有成功。
这是正确的做法吗?有办法实现吗?