Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS: how to delay the launch screen?

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!

like image 854
ishahak Avatar asked Jan 27 '16 03:01

ishahak


5 Answers

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.

like image 92
EmilioPelaez Avatar answered Oct 05 '22 08:10

EmilioPelaez


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
}
like image 29
Xcodian Solangi Avatar answered Oct 05 '22 09:10

Xcodian Solangi


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

like image 24
Xcoder Avatar answered Oct 05 '22 08:10

Xcoder


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

like image 26
GeneCode Avatar answered Oct 05 '22 08:10

GeneCode


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.

like image 33
iBhavin Avatar answered Oct 05 '22 10:10

iBhavin