Search code examples
iossplash-screen

display splash image in iOS app but main thread not sleeping


Hi I have a location based iOS app and I would like to allow main thread running(connecting to server to retrieve info etc) while the splash image is displayed. Currently I set the main thread to sleep to display the splash image for a given time. How can I display splash image for a few seconds while keeping main thread running?


Solution

  • Use a ViewController as the initial viewcontroller with a Splash Image that matches the Launch Storyboard and show/present the main viewcontroller after the location is up to date and other tasks are complete. Don’t mess with the threading. All UI is on the main thread so when you made the main thread sleep the entire app stops.

    If you just want the splash image and the dummy view controller to show for a specific time just use a delay in viewDidAppear.

    let when = DispatchTime.now() + 3 // Show for 3 seconds
    DispatchQueue.main.asyncAfter(deadline: when) {
         // Present/Push/Segue to main app
    }