iosswiftxcodesplash-screentimedelay

How can I delay splash launch screen programmatically in Swift Xcode iOS


I have put an image in imageView in LaunchStoreyboard. How can I delay the time of image programmatically?

Here is the Launch Screen Guideline from Apple.

Here is code for Launch Screen View controller:

import UIKit
class LaunshViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        self.delay(0.4)
    }

    func delay(_ delay:Double, closure:@escaping ()->()) {
        let when = DispatchTime.now() + delay
        DispatchQueue.main.asyncAfter(deadline: when, execute: closure)
    }
}

Solution

  • As of today there is no predefine method from Apple to hold launch screen. Here are some Approaches which are not optimum but works

    Approach #1 Create a Separate ViewController which has Launch logo & create a timer or perform some operation (Like Database/Loads some essential network call) depends on your app type this way you can ready with data before hand & hold the launch screen as well :)

    Approach #2 Not Optimum

    Use Sleep code which holds up the app for a while.

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
            Thread.sleep(forTimeInterval: 3.0)
            // Override point for customization after application launch.
            return true
        }