Apple now wants us to use "scenes" rather than windows and screens to display content in for iPad and iPhone. Now having added the support for scenes I seem to have lost the ability to target iPad or iPhone with Storyboards?
I set my scenes inside plist like this:
This was copied from a new project, as Apple seems to have forgotten to document how to add scenes to an existing app. Another example of Apple not documenting sufficiently!
Now I seem to have lost the ability to use different storyboards for iPad from iPhone.
Whilst I could use the same storyboard for the iPad that I use with the iPhone my app looks better with the dedicated interface I have for the iPad because I use the extra real estate it offers to give a better end user experience. iPhone is fine, the interface is best suited to a small display but looks barren on an iPad.
Help!
2
Answers
There may be a better way to do this, but searching I couldn't see anybody else covering this. Therefore, I'm giving my solution which has been accepted by the App Store here for others to review, use, improve upon, and most importantly, not waste any time on a goose chase looking for a solution that may not exist!
The way I got around this was to add another storyboard and view controller just to handle the decision if it's a iPhone or iPad, and then immediately load up the targeted storyboard. I called this "entry decision". The only issue was when closing the subsequent views you have to ensure that you're doing it correctly or you'll end up back at the "entry decision". And with a blank view, your end user could be stuck. Therefore, to ensure a user can never really be stuck I put buttons in that view so they can manually navigate should it show up if there's a change by Apple further down the line that we don't know about. Best to cover it now.
Step 1, create an new storyboard, "entry decision":
Because I'm a nice person I explain to the user it's an error and apologise. I also give them two buttons, iPad and iPhone. In theory, if all goes well, the end user will never see this, but at no cost to us it's better to cover this possibility.
Step 2, as soon as the view controller is loading get it to move to the right storyboards we actually want.
There's nothing really special about this as it is a mix of detecting which device and then loading the right storyboards. And for full disclosure, I include a reference back to the original code I used for loading those storyboards.
The additional two methods are just the button presses, shown here for completeness.
Step 3, update the scene configuration inside plist to target Entry Decision instead of Main.
You're targeting a different storyboard, hence this needs updated.
Step 4, returning back to your main screen.
In my app, I have a welcome screen, and then table views or other views depending on which it is. Some types work find without any issues, but as I'm using a navigational controller I need to return correctly. Therefore, this one works best for the final "back" command to the main screen:
Other options either went back to the Entry Decision (the fault we covered just in case) or did nothing:
And that is how I'm able to use my existing storyboards, which have been tweaked perfectly for iPhone and iPad over the years of this app's life, and still be able to support Apple's desire to move to scenes. My app needed to use scenes for another purpose, therefore I had no option but to go this route. I went through many attempts to try and trap the scenes as they're getting loaded, but the initial scene seems to get loaded without you, the programmer, getting any options in how it should be or which one to use. You need this pre-view controller to give you that functionality back, and it is one solution which is active in the App Store now.
Be nice.
It’s quite simple (and, as you say, not documented). You need two completely separate scene manifest entries in your Info.plist, i.e.
UIApplicationSceneManifest
andUIApplicationSceneManifest~ipad
. They just specify differentUISceneStoryboardFile
values, and you’re all set just as before scenes came along.