0

I'm trying to make a wrapper that'll add additional functionality if the device is an iPad, if it's not the application should continue though the storyboard without the wrapper.

enter image description here

The wrapper is a View Controller with two container views. The large one is for the main functionality and the small one is for the additional iPad functionality.

The container's connection is dumped right where the normal storyboard entry point would be.

So is there a way to have multiple entry points based on what device is being used? That way one can have the wrapper and the other won't.

Here's whats in AppDelegate

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        // Override point for customization after application launch.

        self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
        let storyboard = UIStoryboard(name: "Main", bundle: nil)

        let iPadEntryViewController = storyboard.instantiateViewControllerWithIdentifier("iPadWrapperView") as! UIViewController
        let iPhoneEntryViewController = storyboard.instantiateViewControllerWithIdentifier("iPhoneEntryPointView")as! UIViewController

        if (/* SOME ACTION */ false) {
            self.window?.rootViewController = iPadEntryViewController
            self.window?.makeKeyAndVisible()

        }
        else {
            self.window?.rootViewController = iPhoneEntryViewController
            self.window?.makeKeyAndVisible()
        }

        return true
    }

So what would go in the if statement to check if the device is an iPad?

Cole
  • 2,641
  • 1
  • 16
  • 34
  • possible duplicate of [Programatically set the initial view controller using Storyboards](http://stackoverflow.com/questions/10428629/programatically-set-the-initial-view-controller-using-storyboards) – Will M. Jul 07 '15 at 19:52
  • Right. I actually used that source to set up my appDelegate. Which is all done except for the if() statement where I could check if the device is an iPad (Which I don't know how to do). I'll update my question to reflect this. – Cole Jul 07 '15 at 20:03
  • http://stackoverflow.com/questions/10167221/ios-detect-if-user-is-on-an-ipad – Will M. Jul 07 '15 at 20:05

1 Answers1

0

Here's how I found how to detect the device and assign an entry point specifically for Swift. Turns out it was a simple enum that could be accessed under UIDevice

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        // Override point for customization after application launch.

        self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
        let storyboard = UIStoryboard(name: "Main", bundle: nil)

        let iPadEntryViewController = storyboard.instantiateViewControllerWithIdentifier("iPadWrapperView") as! UIViewController
        let iPhoneEntryViewController = storyboard.instantiateViewControllerWithIdentifier("iPhoneEntryPointView")as! UIViewController

        if (UIDevice.currentDevice().userInterfaceIdiom == .Phone) {
            self.window?.rootViewController = iPhoneEntryViewController
            self.window?.makeKeyAndVisible()

            println("Application will begin as iPhone app")

        }
        else {
            self.window?.rootViewController = iPadEntryViewController
            self.window?.makeKeyAndVisible()

            println("Application will begin as iPad app")
        }

        return true
    }
Cole
  • 2,641
  • 1
  • 16
  • 34