I am using LaunchScreen.storyboard
for showing the splash screen which is just a static image. Now the problem is i want to show an alert on the top of this splash screen if a particular condition is not met . For this i did the following code . But unfortunately the alert is shown only after the splash screen. How can i show the alert on the top of splash screen? As of now this is the following code which I am implementing but the splash screen does not shows the alert instead it shows only after the splash screen.
func application(_ application: UIApplication, willFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
if conditionMet
{
print("Condition met!")
}
else
{
let storyboard : UIStoryboard = UIStoryboard(name: "Launch Screen", bundle: nil)
let launchScreenCtrler = storyboard.instantiateViewController(identifier: "LAUNCH_SCREEN")
let alertViewFrame = CGRect(x: 100, y: 300, width: 120, height: 80)
let newView : UIView = UIView(frame: alertViewFrame)
launchScreenCtrler.view.addSubview(newView)
launchScreenCtrler.view.bringSubviewToFront(newView)
alert.show(launchScreenCtrler, sender: newView)
}
}
3
Answers
Launch screen does not support any code insertion, it is just "image"screen rendered from Interface builder which is loaded before the app loads itself. I recommend using some other
UIViewController
that will look identical to yourLaunchScreen
and displays right after launchScreen, on this ‘standard’UIViewControler
you can perform any code you want as usual.You can’t control what is visible over
Launch Screen
or for how much time it is displayed.Here’s what you should do –
SplashViewController
that has identical layout asLaunchScreen.storyboard
.SplashViewController
is the first screen to be visible to user in the app.First of all Alert can be presented on View Controller and
I think you should use UIAlertController which is an object which displays an alert message to user
Following is the code you can try it will show the alert on top of ViewController