21

When launch an app, the LaunchScreen.xib is removed as soon as all the assets are initialized.

I want to make the launch screen stay for at least 1 sec.

Is there a way to achieve this?

Thank you!

ishahak
  • 6,585
  • 5
  • 38
  • 56
  • 6
    Rethink this. Users want to use your app, not stare at the launch screen. – rmaddy Jan 27 '16 at 03:48
  • I would only "recommend" (with reservations) this approach for games and other entertainment content that needs to display a credits/licensing splash screen. Otherwise, make your app look like it launches as quick as possible. – Nicolas Miari Jan 27 '16 at 04:28

6 Answers6

29

You can create a view controller that uses the LaunchScreen storyboard, present it (not animated) on applicationDidFinishLaunching or applicationWillFinishLaunching, and dismiss it whenever you want.

Keep in mind this is discouraged by Apple because it gives the impression that your app takes a lot longer to launch, which is bad user experience and might cause some of your users to delete your app.

EmilioPelaez
  • 18,758
  • 6
  • 46
  • 50
  • 5
    I'm accepting this answer although it in not exactly what I wanted, because I don't know for how long was the launch screen already presented. I was hoping for Apple to allow configuration of a minimum time, because users are not happy seeing something for 200 milliseconds and having it gone before they understand what was it... – ishahak Jan 27 '16 at 14:19
  • 2
    That's because the launch screen is not designed to show any content, Apple actually suggests the opposite, for your launch screen to be the main view of your application without content. If you want somewhere to display your logos you could make a fancy `About` screen. Here's Apple's HIG on launch screens. https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/MobileHIG/LaunchImages.html – EmilioPelaez Jan 27 '16 at 14:24
  • @EmilioPelaez I use this approach as well! By far the best approach. It allows us to add animation to the launch screen like the Netflix application. – PhillipJacobs Sep 07 '20 at 12:49
  • @EmilioPelaez - the new dev site moved the content to -> https://developer.apple.com/design/human-interface-guidelines/patterns/launching/ (circa WWDC 2022) – benc Jul 28 '22 at 05:54
21

Swift 4 Update

Just write one line of code Thread.sleep(forTimeInterval: 3.0) in the method of didfinishLauching.... in appdelegate class.

Example

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    Thread.sleep(forTimeInterval: 3.0)
    // Override point for customization after application launch.
    return true
}
Xcodian Solangi
  • 2,342
  • 5
  • 24
  • 52
  • 11
    No, do not do this. Never sleep on the main queue. – rmaddy Jun 05 '19 at 05:42
  • This is working with Xcode 10.4.2 and Swift 5.0. Thanks @Xcodian Solangi – Pankaj Kulkarni Sep 09 '19 at 13:08
  • This is extremely useful when developing using Simulator. Tested with Xcode 11.3.1 and Swift 5. The launch screen often goes by too quickly to see. Waiting just 1 second is enough. Per the other warnings, it's probably good to eliminate the pause for a production release. – Wayne Henderson Mar 22 '20 at 19:48
11

Never sleep on the main thread. Doing this could actually cause iOS to kill your app for taking too long to start up

Xcoder
  • 1,433
  • 3
  • 17
  • 37
2

Thought I chip in my thoughts on this, I wanted to write in comments but it won't allow many lines. I believe many apps developer want to do this (delay the launch screen) is because they want to build a brand presence of the apps/games for their company.

Having said that, launch screen is NOT designed for that, as Rick Maddy explained in the comment section in one of the other answers. Launch screen's purpose is to make users feel the app is instantly running by showing the empty UI while the actual data is loading at the back (willAppear and so on).

So to achieve what many developers want, while being in-line with Apple's HIG, what you can do is:

  1. Display UI template in the launchscreen as intended by Apple HIG.
  2. Upon main screen load, load up another VC that shows "intro" of your brand. Make sure this runs only ONCE (a simple flag in NSUserDefaults should do the trick).
  3. Users should be allowed to skip this if it is a long "intro".

The same "intro" VC should be available to user by tapping on a "View Intro" button somewhere (maybe in about page).

GeneCode
  • 7,545
  • 8
  • 50
  • 85
1

If you want to go with simple, you can use NSThread:

[NSThread sleepForTimeInterval:(NSTimeInterval)];

You can put this code into the first line of applicationDidFinishLaunching method.

For example, display default.png for 1.0 seconds.

- (void) applicationDidFinishLaunching:(UIApplication*)application
{
   [NSThread sleepForTimeInterval:1.0];
}

It will stop splash screen for 1.0 seconds.

iBhavin
  • 1,261
  • 15
  • 30
  • 11
    **Never** sleep on the main thread. Doing this could actually cause iOS to kill your app for taking too long to start up. – rmaddy Jan 27 '16 at 04:21
  • 1
    It's still wrong. That time should be used to get the app going, not just sit there doing nothing. – rmaddy Jan 27 '16 at 04:24
  • 2
    It's according to the question. – iBhavin Jan 27 '16 at 04:25
  • 1
    That doesn't make it a proper or good solution. The other answer explains the proper solution (even though it's a bad idea to show the launch screen any longer than necessary). – rmaddy Jan 27 '16 at 04:27
  • Ok, that's might be right and i keep in mind, but I believe in shorter solution that achieves what I want. – iBhavin Jan 27 '16 at 04:29
  • @rmaddy I agree with your statement. But do you have any other better way to achieve it. – Tester Jun 05 '19 at 05:39
0

Alhamdulellah Solution is find

Only copy and paste this code in AppDelegate Class
Call this SplashScreenTiming() in didFinishLaunchingWithOptions()

private func SplashScreenTiming(){

    let LunchScreenVC = UIStoryboard.init(name: "LaunchScreen", bundle: nil)
    let rootVc = LunchScreenVC.instantiateViewController(withIdentifier: "splashController")
    
    self.window?.rootViewController = rootVc
    self.window?.makeKeyAndVisible()
    Timer.scheduledTimer(timeInterval: 5, target: self, selector: #selector(DismissSpalshController), userInfo: nil, repeats: false)
}
@objc func DismissSpalshController(){
    let mainVC = UIStoryboard.init(name: "Main", bundle: nil)
    let rootvc = mainVC.instantiateViewController(withIdentifier: "SignInVC")
    self.window?.rootViewController = rootvc
    self.window?.makeKeyAndVisible()
    
}
M Hamayun zeb
  • 448
  • 4
  • 10