Execute code in Launch Screen Execute code in Launch Screen ios ios

Execute code in Launch Screen


No, it's not possible.

When launch screen is being displayed your app will be in loading state.

Even the - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions will not be completely executed while the launch screen is displayed.

So it's clear that, you don't have any access to your app and so at this point you can't execute any code.


I was trying to do the same thing here. :)

I really liked some of the apps, in which they do a little dynamic greeting text and image each time the app is launched, such as "You look good today!", "Today is Friday, a wonderful day", etc, which is very cute.

I did some search, below is how to do it:(My code is XCode 7, with a launchscreen.xib file)

class AppDelegate: UIResponder, UIApplicationDelegate {    var window: UIWindow?    var customizedLaunchScreenView: UIView?    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {        // Override point for customization after application launch.        application.statusBarHidden = true        // customized launch screen        if let window = self.window {            self.customizedLaunchScreenView = UIView(frame: window.bounds)            self.customizedLaunchScreenView?.backgroundColor = UIColor.greenColor()            self.window?.makeKeyAndVisible()            self.window?.addSubview(self.customizedLaunchScreenView!)            self.window?.bringSubviewToFront(self.customizedLaunchScreenView!)            UIView.animateWithDuration(1, delay: 2, options: .CurveEaseOut,                                       animations: { () -> Void in                                        self.customizedLaunchScreenView?.alpha = 0 },                                       completion: { _ in                                        self.customizedLaunchScreenView?.removeFromSuperview() })        }        return true    }// other stuff ...}

Just do what ever you wanted to show, text, images, animations, etc. inside the customizedLaunchScreenView here.

At the end of the launching, just fade out this customized UIView using alpha value change, then remove it completely.

How cool is that? I absolutely love it!

Hope it helps.


I was also trying to achieve this. I tried the following, it gives a delay of couple of seconds but works for me.

  • Create and set a launch screen in project settings.
  • Create a view controller with custom class (SplashViewController) and set it your starting view controller in storyboard.
  • Add a container view in it and set it to full screen.
  • Set embedded segue to a Storyboard Reference.
  • Select Storyboard Reference and set launch screen in StoryBoard property from Attribute inspector.
  • Do whatever you want in SplashViewController (play animation or session check etc) and perform segue when done.

Hope it helps!