Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

Can't get LaunchScreen.storyboard to work! Need docs.

Discussion in 'iOS and tvOS' started by tessellation, Apr 3, 2018.

  1. tessellation

    tessellation

    Joined:
    Aug 11, 2015
    Posts:
    102
    Unity 2017.3.1p3 copies my storyboard to the Xcode project, but there doesn't seem to be a way to include images in an xcassets folder. When I manually add the xcassets in Xcode, the launch screen storyboard appears correctly, but Unity crashes on startup:

    Uncaught exception: NSInvalidArgumentException: Storyboard (<UIStoryboard: 0x1664c580>) doesn't contain a view controller with identifier 'unitySplashStoryboard'

    0 CoreFoundation 0x21a29b23 <redacted> + 150
    1 libobjc.A.dylib 0x211e6dff objc_exception_throw + 38
    2 UIKit 0x267143d9 <redacted> + 0
    3 GameAppName 0x00049ff4 _Z16ShowSplashScreenP8UIWindow + 548
    4 GameAppName 0x0006d3cc -[UnityAppController(ViewHandling) createUI] + 2160
    5 GameAppName 0x000698f0 -[UnityAppController application:didFinishLaunchingWithOptions:] + 1856


    Can someone from Unity please document how to make this work? Thanks!
     
  2. tessellation

    tessellation

    Joined:
    Aug 11, 2015
    Posts:
    102
  3. tessellation

    tessellation

    Joined:
    Aug 11, 2015
    Posts:
    102
    I've been digging into this some more by looking at the Unity source code in XCode. What it looks like to me is that in the SplashScreen.mm code, ShowSplashScreen() wants a UIViewController with ID 'unitySplashStoryboard' so I added that to my storyboard. That fixes the first crash above, but then it crashes in ShowSplashScreen() a few lines later when it calls [_controller create: window] because UIViewController doesn't contain the 'create' selector. It clearly is looking for _controller to be a SplashScreenController instance, but it isn't possible to assign custom classes (like SplashScreenController) to LaunchScreen storyboards, so I don't get how this code is supposed to work?
     
    cloutiertyler likes this.
  4. tessellation

    tessellation

    Joined:
    Aug 11, 2015
    Posts:
    102
  5. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    3,552
    This doesn't sound familiar. Are you able to file a bug report so I can look into it?
     
  6. tessellation

    tessellation

    Joined:
    Aug 11, 2015
    Posts:
    102
    Thanks @karl_jones ! - Yes, I filed a bug, the fogbugz number is 1023109

    I included a LaunchScreen.storyboard and xcassets with images for it with the bug post.

    Hopefully there's a fix I can make in the IOS Trampoline source (i.e. Classes/UI) so I don't have to wait for an official patch. :)
     
    cloutiertyler and karl_jones like this.
  7. tessellation

    tessellation

    Joined:
    Aug 11, 2015
    Posts:
    102
    Hi @karl_jones, did that bug post have enough information?
     
  8. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    3,552
    Its with QA at the moment. Looks like they have been discussing it with you via email.
     
  9. tessellation

    tessellation

    Joined:
    Aug 11, 2015
    Posts:
    102
    @karl_jones, yes, they've reproduced it and passed it on to the engineers.
     
    karl_jones likes this.
  10. Masterfalcon

    Masterfalcon

    Unity Technologies

    Joined:
    Dec 29, 2014
    Posts:
    362
    Out of curiosity, if you make your storyboard controller have a custom class of SplashScreenController with storyboard ID unitySplashStoryboard does it work as expected? I've attached a screen shot for reference.

    There were supposed to be some docs for this but they must have fallen through the cracks. I'll see what I can do about that.
     

    Attached Files:

    karl_jones likes this.
  11. tessellation

    tessellation

    Joined:
    Aug 11, 2015
    Posts:
    102
    No that doesn't work because storyboards do not allow custom classes.

    Thanks, that would be very helpful!
     
    cloutiertyler likes this.
  12. Masterfalcon

    Masterfalcon

    Unity Technologies

    Joined:
    Dec 29, 2014
    Posts:
    362
    True, but the view controller instance in your storyboard does allow custom classes.
     
  13. tessellation

    tessellation

    Joined:
    Aug 11, 2015
    Posts:
    102
    I'm not sure what your point is. If you try to compile with that storyboard using a custom class as a launch screen storyboard, you'll get an error. My experience is that launch storyboards only work with core classes, like UIViewController. It will not work with a derived custom class.
     
    cloutiertyler likes this.
  14. Masterfalcon

    Masterfalcon

    Unity Technologies

    Joined:
    Dec 29, 2014
    Posts:
    362
    I've done some work on this and your changes to ShowSplashScreen() are absolutely right.

    In SplashScreen.mm, ShowSplashScreen() should look like this:


    void ShowSplashScreen(UIWindow* window)
    {
    _controller = [[SplashScreenController alloc] init];

    [_controller create: window];
    [window makeKeyAndVisible];
    }


    Further, make sure that iPhone and iPad Launch Screen type is set to None in the Splash Screen section of the PlayerSettings Inspector.
     
    jackj31416 likes this.
  15. tessellation

    tessellation

    Joined:
    Aug 11, 2015
    Posts:
    102
    Thanks @Masterfalcon - while that fixes the crash, I don't think that's the expected solution because then there's a black screen after this and before the Unity Splash screen. I noticed there is code elsewhere in the Unity IOS startup code (I don't recall where at the moment) - where it tries to display the storyboard. This is a good thing as I think it's trying to avoid having a black screen by displaying the Launch Storyboard again. However, I believe this code to display the Launch Storyboard again is broken. The fix above avoids this code, but that is not ideal.

    Also there's no way to have xcasset images with your Storyboard. Unity needs to find and copy those associated assets to the IOS (XCode) project folder and add it to the XCode solution/project file.
     
  16. Masterfalcon

    Masterfalcon

    Unity Technologies

    Joined:
    Dec 29, 2014
    Posts:
    362
    Which other code do you see that is a problem?

    I think the xcasset bundle thing is a separate issue, I'll it discuss with the team.
     
  17. tessellation

    tessellation

    Joined:
    Aug 11, 2015
    Posts:
    102
    Sorry, in that method ShowSplashScreen, it creates the view controller from the storyboard to avoid that black screen. Elsewhere above in the SplashScreen class, it checks if the storyboard is being used and it doesn't show the Launch Images or "nib" file alternative. If you remove that code as you suggest in ShowSplashScreen, then you get black after the Storyboard launch screen, which looks bad.
     
  18. owiesniak

    owiesniak

    Joined:
    Jan 27, 2018
    Posts:
    3
    I'm facing the same problem. Changing `ShowSplashScreen` as Masterfalcon mentioned above works (application is booting again) but it does not look good because it is immediate fading to black.
     
  19. Masterfalcon

    Masterfalcon

    Unity Technologies

    Joined:
    Dec 29, 2014
    Posts:
    362
    I actually have a fix for that as well. I'm attaching a diff that you can apply to SplashScreen.mm to fix both issues.
     

    Attached Files:

    jackj31416, WereVarg and tessellation like this.
  20. WereVarg

    WereVarg

    Joined:
    Apr 9, 2012
    Posts:
    18
    Any ETA when it will be in the release versions?
     
    cloutiertyler likes this.
  21. tessellation

    tessellation

    Joined:
    Aug 11, 2015
    Posts:
    102
    @Masterfalcon Will this be included in the LTS releases? 2017.4?
     
  22. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    5,999
    I've stumbled upon this as well. It's still not fixed in Unity 2018.1.6f1.

    I've been happily using the simple iPhone/iPad Launch screens, until I found out that they cause Screen.safeArea to return wrong values for some reason ( Case 1052565 ). So I tried the built in Unity Splash Screen stuff, but I don't want it to fade in and out, and 2 seconds it too long and it seems that I can't set it to be shorter than that.

    So I thought I'd create a Storyboard and use that. So I made it, added it to my Unity project and then I was stumbled as to how I'd also add an image to go with it in the build. Seems it isn't possible (?). So I added the image manually and it also crashed for me.

    Then I came here.

    I applied the patch posted here, and even though it works now, it seems it doesn't handle the orientation correctly.

    I have the orientation set only for landscape in the General settings and it's set to only landscape in info.plist. But still, if I have my iPhone 6S Plus in portrait when I launch my app, the storyboard I provided switches to portrait for half a second, which is annoying and looks weird.

    I have to say it has been frustrating that none of the built in methods that Unity provides work correctly for me.
     
    WereVarg likes this.
  23. plasticYoda

    plasticYoda

    Joined:
    Aug 20, 2013
    Posts:
    61
    So I upgraded a project to Unity2018.3 that had a working storyboard splash screen and got the following exception on launch:

    *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Application windows are expected to have a root view controller at the end of application launch'

    I switched to a simple test project, and copied my storyboard over and I get the same error. After some further testing and tweaking, I've discovered that by replacing this line:

    _controller = [storyboard instantiateInitialViewController];

    with

    _controller = [storyboard instantiateViewControllerWithIdentifier: @"unitySplashStoryboard"];

    in SplashScreen.mm.

    The line came from the previously working SplashScreen.mm as part of Unity2017.

    The app will launch and show the storyboard as expected. Can anyone @Unity or @Masterfalcon illustrate how this is supposed to work?
     
  24. Masterfalcon

    Masterfalcon

    Unity Technologies

    Joined:
    Dec 29, 2014
    Posts:
    362
    In either project is your storyboard viewcontroller set as the Initial View Controller in Xcode?
     
  25. plasticYoda

    plasticYoda

    Joined:
    Aug 20, 2013
    Posts:
    61
    In the 2nd test project, everything is as default in Unity2018.3, except I checked the 'use storyboard' option in the build settings, created a storyboard file (used previously working storyboard from my 2017 project, less the background image), and then modified the SplashScreen.mm file as per my previous post after building the project once.

    So I don't explicitly set the initial ViewController, its just whatever the normal unity launcher does.
     
  26. Masterfalcon

    Masterfalcon

    Unity Technologies

    Joined:
    Dec 29, 2014
    Posts:
    362
    Ah ok. I think what you'll want to do(I haven't tried this yet today) is select the View Controller in your storyboard and set Use as Launch Screen(see the first screenshot). Then also check Is Initial View Controller (second screenshot). Hopefully that will do the trick.
     

    Attached Files:

  27. plasticYoda

    plasticYoda

    Joined:
    Aug 20, 2013
    Posts:
    61
    That let the standard 2018.3 code launch without error. I had to recreate a new storyboard file, the one I'd used previously had a custom class name, and that was generating an error. Also, the storyboard must be called "LaunchScreen.storyboard" and I had to manually add it to the XCode project generated by Unity.

    However, this should let me upgrade to 2018.3.

    Thanks.