Execute Code in Launch Screen

Execute Code in Launch Screen UPDATED

It is not possible to write any custom class/code for the launchscreen xib/storyboard files. We can only design using resource files.

Swift - Execute code on LaunchScreen

As you wrote, LaunchScreen is there before your app is ready and it implies that you can't execute your code in this time.

To achieve something similar, copy & paste content of your LaunchScreen into your initial view controller in your Main storyboard (or whatever you do use) and launch your request in initial view controller and then transition to any other view controller.

User is not going to notice LaunchScreen -> Main transition.

Purpose of LaunchScreen is to just replace splash images with something better where you can use auto layout for example, ... In other words, to minimize your work, so, you're not forced to create splash screen for every device screen size, etc. But you are not allowed to run any logic in LaunchScreen.

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.

Is there any way to code the LaunchScreen programmatically

No, The launch screen is shown before your app starts executing in order to provide a transition from the Springboard to your app while it is loading.

You can either use a fixed image or you can use a simple storyboard scene using only standard, static UI elements - labels & images.

This storyboard scene is actually loaded and displayed by the OS, so it would be a security risk to allow your code to execute in that context.

iOS Launch screens with logic

No, not possible. The launch screen is not rendered by your app, but by the system, so it is static.

Note that the launch screen is is not a fully customizable view controller. You cannot specify a custom class name in the storyboard and expect the system to give you the option to execute code at this stage by calling viewDidLoad. Remember, the app hasn’t launched yet.

(According to this site)

Also it appears that you cannot change the launch image programatically, as discussed in this question.

Replace Launch screen text on each app login

You can't assign custom VC to that launch (only static images or text dragged from Object Library ) , if you want to make splash make it in the rootVC then navigate to the mainVC

iOS Launch screen code not running

You're not doing anything wrong.

No code is associated with the launch screen. You can't run any logic. It is purely there so that you can use AutoLayout to layout the launch screens for different sizes of device.



Related Topics



Leave a reply



Submit