11

How can I delay the app loading to show the splash screen for longer?

Moshe
  • 57,511
  • 78
  • 272
  • 425

6 Answers6

26

You should let the app start as usual then make the first view that appears have the identical image on it as the splash screen. Start a timer and then replace that view with your real application root view after a few seconds.

Deliberately delaying the actual application launch is a big no-no.

toholio
  • 2,888
  • 2
  • 22
  • 21
  • 7
    As does Apple: http://developer.apple.com/iphone/library/documentation/UserExperience/Conceptual/MobileHIG/HandleTasks/HandleTasks.html#//apple_ref/doc/uid/TP40006556-CH16-SW2 "Avoid displaying an About window, a splash screen, or providing any other type of startup experience that prevents people from using your application immediately." – Brad Larson Mar 17 '10 at 12:31
  • 4
    Sheesh, just asking. If apple has an issue they can scold me themselves. They're quite capable. :) – Moshe Mar 18 '10 at 14:44
  • 2
    @Moshe: It's better that you hear it from us than Apple (after weeks in review), or worse yet, your users. In any case, we're not trying to scold, just point out our opinions on the topic. I tend to defer to Apple when it comes to UI matters, because they've put a lot of thought into this. – Brad Larson Mar 18 '10 at 18:12
  • While the general rule is that you should not use sleep on app load, I would not say you should never do it. Particularly on simple apps that load very, very fast. There is no difference to the user or to Apple if you put the thread to sleep for a short amount of time or use switch out the default image on load. Probably a lot of people will flame me for this, but if your app loads in .1 seconds, does it really matter if you sleep for .3 seconds so users can get a glimpse of your splash screen? Better than the added overhead of switching out a view, IMO. – memmons Nov 12 '10 at 19:13
  • 1
    @Brad - That said, they've let through PLENTY of apps with splash screens. One of mine needs to preload some data on launch, and there's really no better way than to put up a view that is my splash screen with a progress view on it. – Dan Ray Mar 04 '11 at 18:11
  • 1
    @Harkonian: `Default.png` is to let the user have immediate feedback that the app is launching. It's not there to show a splash screen and delaying it so that the user can see the splash screen for longer is the exact opposite of what it's meant for. If your simple app loads very quickly, that's a *good* thing, not a bug to be fixed, and you should make `Default.png` a static image of your initial user interface. – Jim Mar 04 '11 at 18:30
  • You are the artist of your app, not Apple, and art does not always take kindly to rules. By the way, going against the grain is exactly what made Apple Apple. – trndjc Jun 14 '18 at 23:42
11

UPDATE: No seriously, DON'T do this!

Or us the C function

sleep(9);

Putting this in applicationDidFinishLaunching: will cause you program to pause for 9 seconds, any other integer may be entered as well.

EDIT: I've learned a lot in the past year. Don't do this. The reason being that the springboard will automatically stop the app launching if it takes too long. That timing is poorly documented so even one second can result in the app failing.

  • 9 is waaay to long, but perhaps one second. Can I put in a float (I.e: 1.5)? – Moshe Mar 18 '10 at 14:45
  • I was just throwing out a number. You can use any int you want, but it does have to be an int. – Dustin Pfannenstiel Mar 19 '10 at 11:02
  • 3
    -1. Never put a big delay or anything time intensive in applicationDidFinishLaunching. Use a timer in another thread or something similar; but return quickly from applicationDidFinishLaunching. See http://stackoverflow.com/questions/169470/does-the-iphone-timeout-if-a-function-takes-too-long-to-execute – occulus Sep 27 '12 at 14:54
  • 1
    This sort of delay is also helpful when you want to see how your launch screen xib is rendering. – Clifton Labrum Oct 02 '14 at 00:19
1

This question is similar: splash screen like tap tap revenge 3

Basically, in your applicationDidFinishLaunching:, add an image view on top of other views containing your Default.png.

Community
  • 1
  • 1
Ben Gottlieb
  • 85,404
  • 22
  • 176
  • 172
1

See the above discussion of why you probably should not delay your app load in this way. But if you happen to have a scenario where sleeping for short duration would be preferable to the overhead of switching out a view, use NSThread's sleepForTimeIntervale instead of sleep(). It's more framework friendly and you have more granular control over the sleep time:

[NSThread sleepForTimeInterval:0.75]
memmons
  • 40,222
  • 21
  • 149
  • 183
  • The problem with this approach is that it blocks everything. If you press the home button during the sleep interval, nothing will happen. Try it out with a larger sleep interval and it's more obvious. – greenisus Dec 15 '10 at 06:22
0

I had a situation where the client had to demo the launch image. So, this was my solution..

- (void)applicationDidBecomeActive:(UIApplication *)application

{

UIImageView *defaultImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Default@2x.png"]];
[self.window addSubview:defaultImageView];
sleep(2);
[defaultImageView removeFromSuperview];
[defaultImageView release];
/*
 Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
 */

}

Mobilewits
  • 1,743
  • 4
  • 21
  • 34
0

You can use it sleep method to get this result "

sleepForTimeInterval

", If you want to get it launch time, do like :

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

It will delay the launch by 8 seconds

Warning : But it is not recommended by apple, as it will the watchdod about long time for your app loading, It can kill your app. But incase if you need it to get some specific screenshot or for some in-house use, you can use to solve for purpose but never in app submission.

Ash
  • 5,525
  • 1
  • 40
  • 34