GO FURTHER, FASTER: Try the Swift Career Accelerator today! >>

MainView visibility on .inactive ScenePhase

Forums > SwiftUI

On my app I use the typical way for biometric authentication after coming back from background:

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

Doing this way everything works OK, but there is a little moment MainView is visible BEFORE authentication method triggers, I supossed due to the fraction of time that app is .inactive, after coming back from .background.

On MacOS app version, I call this authentication method on AppDelegate "applicationDidFinishLaunching" method, and nothing at all is presented until authentication finishes. So, I've tried to emulate this on iOS, with a dedicated AppDelegate, and trying some methods, without success.

Is this the correct way of doing it? Is there a way to accomplish it?

2      

Hacking with Swift is sponsored by Alex.

SPONSORED Alex is the iOS & Mac developer’s ultimate AI assistant. It integrates with Xcode, offering a best-in-class Swift coding agent. Generate modern SwiftUI from images. Fast-apply suggestions from Claude 3.5 Sonnet, o3-mini, and DeepSeek R1. Autofix Swift 6 errors and warnings. And so much more. Start your 7-day free trial today!

Try for free!

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.