SwiftUI - How to make app don't show default LaunchScreen/ SplashScreen?

Viewed 3409

I am developing a SwiftUI app, there I added a custom splash screen, But now my app is showing 2 splash screens one is blank(the default one) and other is the one that I created.

How can I set the set App to Launch the App from my MainView.

In swift5, in storyboard view we can set this here enter image description here How to achieve this same functionality in swiftUI?

Actually I don't want to delete the splash permanently, I want to put my own custom splash displaying animated video without any video controllers.. e.g play, pause..etc.

Edit 1: Adding Same behavior of SwiftUI

Below is the current behavior of SwiftUI: , it is not showing any option to select...

enter image description here

Edit 2: Adding Project Navigator Screenshot

enter image description here

4 Answers

First, delete your unwanted launch screen inside the project navigator. Then:

  1. Select your desired launch screen, then check "Use as Launch Screen" in the attributes inspector

"Use as Launch Screen" is checked

  1. Make sure that the launch screen's sole view controller is the initial view controller

"Is Initial View Controller" is checked

  1. In swift5, in storyboard view we can set this here

It's the same for both UIKit and SwiftUI. To set the launch screen, just select it for "Launch Screen File."

Project -> Targets -> Launch Screen File

After creating a SwiftUI app with the App lifecycle, then following the above steps, here's my result:

App launches with custom launch screen

You can set this in Info.plist -> Launch Screen

enter image description here

iOS does not allow users to remove the splash screen. This is for safety and cataloguing reasons. Removing it in Info.plist doesn't actually remove it for public users. Use the default arrangement instead of creating your own.

If you submit the app, it will be rejected without the use of a proper splash screen.

https://developer.apple.com/forums/thread/28332

in my case I wanted to use a custom Lottie animation and then move to my view, I created this view to host my splash and transition to my app's home screen when it's done playing

struct Splash<Splash: View, Content: View>: View {

    var splashDuration: CGFloat = <#Duration#>
    @State var showingSplash: Bool = true

    var splash: Splash
    var content: Content

    init(@ViewBuilder splash: () -> Splash,
         @ViewBuilder content: () -> Content) {
        self.splashDuration = splashDuration
        self.splash = splash()
        self.content = content()
    }

    var body: some View {
        if showingSplash {
            splash
                .onAppear { scheduleHideSplash() }
                .transition(.opacity.animation(.default))
        } else {
            content
                .transition(.opacity.animation(.default))
        }
    }

    func scheduleHideSplash() {
        DispatchQueue.main
            .asyncAfter(deadline: .now() + splashDuration) {
            showingSplash = false
        }
    }
}

usage:

    Splash {
        SplashAnimationView()
    } content: {
        Color.blue.ignoresSafeArea()
    }
Related