I am trying to put a first launch view. I already tried some stuff but that won\'t work.
Here is what I have:
- (BOOL)application:(UIApplication *)a
I have the solution in Swift and have published an example on GitHub to share:
https://github.com/AppLogics/DynamicEntryPointExample-iOS
I will explain here with a simplified version of it to dynamically/programmatically set the Entry Point from between a blue and a red View Controller.
Ensure in interface builder you remove all entry points from your storyboard, in order to do this you will need to select the ViewController
with the Entry Point
and uncheck the Is Initial View Controller
option under the View Controller
section:
You then need to ensure all potential entry points are assigned Storyboard Id
's as you will use this in code from the AppDelegate.swift
file. This example uses blue
and red
Next you must edit the AppDelegate.swift
file. First declare the constant to test against and decide which View Controller to display initially, in this case:
let blueEntryPoint = true
Next insert some code in the default didFinishLaunchingWithOptions
function between the comment: // Override point for customization after application launch.
and the statement: return true
like so:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
//checking to see if the blue is true or false
if blueEntryPoint {
//Showing blue View Controller
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let mainViewController = storyboard.instantiateViewController(withIdentifier: "blue")
self.window = UIWindow(frame: UIScreen.main.bounds)
self.window?.rootViewController = mainViewController
self.window?.makeKeyAndVisible()
} else {
//Not showing blue, i.e. will show red View Controller
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let surveyViewController = storyboard.instantiateViewController(withIdentifier: "red")
self.window = UIWindow(frame: UIScreen.main.bounds)
self.window?.rootViewController = surveyViewController
self.window?.makeKeyAndVisible()
}
return true
}
Run this, then change the blueEntryPoint
to false
and re-run it!