TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

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

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

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

Reply to this topic…

You need to create an account or log in to reply.

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.