4

I have a launchscreen with a image, so far working well.

But now I have 3 schemas: dev, hom and prod.

I would to know how to change the launch screen image according the schema selected at the build time?

EDIT

I have in mind two options, but I do not know which one is best:

Option 1: Create two storyboards and create a variable to set the name of the correct storyboard in the app delegate. This variable I will use in the Info.plist key (Launch screen interface file base name).

Option 2: Create two scenes at the Launchscreen.storyboard and programatically set the correct scene according the enviroment.

Luciano Borges
  • 817
  • 3
  • 12
  • 31
  • I think it is not possible because the Xcode user interface not providing this type of facility. – Pramod Tapaniya Sep 06 '17 at 12:58
  • I think that at beast you can add your own splash screen right after the default launch screen to display your image – David Pilkington Sep 06 '17 at 13:25
  • Each splash screen corresponds to an environment, so I should launch the correct splash. I have in mind two options, but I do not know which one is best. I edit the question to show these options. – Luciano Borges Sep 06 '17 at 13:29
  • There's a slightly tricky way to do this, which is to create a script in the Build Phase that checks the build configuration variable to update in Info.plist the name of the launch image/screen you want to use. – Guy Kogus Sep 06 '17 at 13:39

2 Answers2

2

Use targets, add a target for each environment, each target will have its own info.plist and you just set a different launch screen storyboards for each target , set it once in the relevant info.plist and you ready to select any target and run.

Oleg Sherman
  • 2,772
  • 1
  • 21
  • 20
  • 1
    I had created 3 schemas, each for an environment (dev, hom, prod), because I need to load some variables according to the requested environment. Now, I created a new ImageAsset for a given environment (hom). How to configure when I request to build this environment load the correct asset? – Luciano Borges Sep 08 '17 at 13:36
  • 1
    Will I have to create two storyboards? Can not have a single storyboard and only change the images? – Luciano Borges Sep 08 '17 at 18:16
1

Your second option definitely won't work, since you cannot execute any code on a LaunchScreen and the LaunchScreen is displayed before any code could be executed (even in your AppDelegate), so you cannot change the LaunchScreen file in runtime.

Your first option is almost correct. Indeed a viable solution could be creating several Storyboards for the different launch screens, but you need to tweak the Info.plist file in a build script, you cannot do this in runtime either. Be aware that I haven' actually tested this method, but in theory it should work.

Dávid Pásztor
  • 51,403
  • 9
  • 85
  • 116