4

Configure Different Launch screens based on URL Scheme

 1 year ago
source link: https://sarunw.com/posts/launch-screen-url-scheme/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Launch screen is a screen that displays while your app launches.

A launch screen's sole purpose is to reduce the launch time by showing part of the UI while the app is loading.

Here is an example of a launch screen for the Safari app. As you can see, a launch screen mimics what users will see once the app is fully loaded.

A launch screen for the Safari app.

A launch screen for the Safari app.

Multiple Entry Point

What if your app supports deep links, and the first screen is changed based on the URL Scheme? Which screen should you use for the launch screen?

Luckily, in iOS 14, you can have multiple launch screens which show up based on the URL scheme you supported.

You can easily support sarunw.com by checking out this sponsor.

Translate your app In 1 click:

Sponsor sarunw.com and reach thousands of iOS developers.

UILaunchScreens

To support multiple launch screens, you need to use Launch Screens (UILaunchScreens) key instead of UILaunchScreen (Info.plist launch screen) or UILaunchStoryboardName (Storyboard launch screen).

To define multiple launch screens:

  1. Remove unused launch screen key. It can be either UILaunchScreen or UILaunchStoryboardName. This should avoid conflict and confusion that might occur.
  2. Add Launch Screens (UILaunchScreens) key. This is a dictionary with three keys.
  • Launch Screen Definitions (UILaunchScreenDefinitions).
  • Default Screen Identifier (UIDefaultLaunchScreen).
  • URL to Launch Screen Associations (UIURLToLaunchScreenAssociations).
UILaunchScreens

UILaunchScreens

Let's see what each key is all about.

UILaunchScreenDefinitions

Launch Screen Definitions (UILaunchScreenDefinitions) is an array of all of your supported launch screens.

You put each screen in the form of a dictionary. You use the same structure that you use to define a launch screen in UILaunchScreen.

The only difference is you need to add Identifier (UILaunchScreenIdentifier) key that uniquely identifies the screen.

In this example, I create three launch screens with a different background color.

Declare three launch screens.

Declare three launch screens.

UIDefaultLaunchScreen

Default Screen Identifier (UIDefaultLaunchScreen) key is quite straightforward. You put the identifier of the launch screen you want to use as a default one here.

In this example, I choose "BlueScreen" as the default launch screen.

Set the default launch screen with UIDefaultLaunchScreen key.

Set the default launch screen with UIDefaultLaunchScreen key.

UIURLToLaunchScreenAssociations

URL to Launch Screen Associations (UIURLToLaunchScreenAssociations) key is a dictionary that map between a URL scheme and a launch screen you want to use.

Let's say I have three URL Schemes, red, blue, and green.

URL Schemes.

URL Schemes.

I can map them to different launch screens with this dictionary.

UIURLToLaunchScreenAssociations

UIURLToLaunchScreenAssociations

Here is the final result.

<key>UILaunchScreens</key>
<dict>
<key>UIDefaultLaunchScreen</key>
<string>GreenScreen</string>
<key>UILaunchScreenDefinitions</key>
<array>
<dict>
<key>UIColorName</key>
<string>Green</string>
<key>UILaunchScreenIdentifier</key>
<string>GreenScreen</string>
</dict>
<dict>
<key>UIColorName</key>
<string>Red</string>
<key>UILaunchScreenIdentifier</key>
<string>RedScreen</string>
</dict>
<dict>
<key>UIColorName</key>
<string>Blue</string>
<key>UILaunchScreenIdentifier</key>
<string>BlueScreen</string>
</dict>
</array>
<key>UIURLToLaunchScreenAssociations</key>
<dict>
<key>blue</key>
<string>BlueScreen</string>
<key>green</key>
<string>GreenScreen</string>
<key>red</key>
<string>RedScreen</string>
</dict>
</dict>

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK