iOS/tvOS: Try to load the launch screen as a storyboard. Xcode 8 compiles it as a storyboard instead of a nib.
authorAlex Szpakowski
Sat, 24 Sep 2016 23:33:49 -0300
changeset 103684842604f647a
parent 10367 e88a4e5539e5
child 10369 001cbf1fda90
iOS/tvOS: Try to load the launch screen as a storyboard. Xcode 8 compiles it as a storyboard instead of a nib.
src/video/uikit/SDL_uikitappdelegate.m
     1.1 --- a/src/video/uikit/SDL_uikitappdelegate.m	Sat Sep 24 20:12:57 2016 -0300
     1.2 +++ b/src/video/uikit/SDL_uikitappdelegate.m	Sat Sep 24 23:33:49 2016 -0300
     1.3 @@ -129,12 +129,17 @@
     1.4  
     1.5  - (instancetype)init
     1.6  {
     1.7 +    return [self initWithNibName:nil bundle:[NSBundle mainBundle]];
     1.8 +}
     1.9 +
    1.10 +- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
    1.11 +{
    1.12      if (!(self = [super initWithNibName:nil bundle:nil])) {
    1.13          return nil;
    1.14      }
    1.15  
    1.16 -    NSBundle *bundle = [NSBundle mainBundle];
    1.17 -    NSString *screenname = [bundle objectForInfoDictionaryKey:@"UILaunchStoryboardName"];
    1.18 +    NSString *screenname = nibNameOrNil;
    1.19 +    NSBundle *bundle = nibBundleOrNil;
    1.20      BOOL atleastiOS8 = UIKit_IsSystemVersionAtLeast(8.0);
    1.21  
    1.22      /* Launch screens were added in iOS 8. Otherwise we use launch images. */
    1.23 @@ -357,9 +362,28 @@
    1.24       * displayed (e.g. if resources are loaded before SDL_GL_SwapWindow is
    1.25       * called), so we show the launch screen programmatically until the first
    1.26       * time events are pumped. */
    1.27 -    UIViewController *viewcontroller = [[SDLLaunchScreenController alloc] init];
    1.28 +    UIViewController *vc = nil;
    1.29 +
    1.30 +    NSString *screenname = [bundle objectForInfoDictionaryKey:@"UILaunchStoryboardName"];
    1.31  
    1.32 -    if (viewcontroller.view) {
    1.33 +    if (screenname && UIKit_IsSystemVersionAtLeast(8.0)) {
    1.34 +        @try {
    1.35 +            /* The launch storyboard is actually a nib in some older versions of
    1.36 +             * Xcode. We'll try to load it as a storyboard first, as it's more
    1.37 +             * modern. */
    1.38 +            UIStoryboard *storyboard = [UIStoryboard storyboardWithName:screenname bundle:bundle];
    1.39 +            vc = [storyboard instantiateInitialViewController];
    1.40 +        }
    1.41 +        @catch (NSException *exception) {
    1.42 +            /* Do nothing (there's more code to execute below). */
    1.43 +        }
    1.44 +    }
    1.45 +
    1.46 +    if (vc == nil) {
    1.47 +        vc = [[SDLLaunchScreenController alloc] initWithNibName:screenname bundle:bundle];
    1.48 +    }
    1.49 +
    1.50 +    if (vc.view) {
    1.51          launchWindow = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    1.52  
    1.53          /* We don't want the launch window immediately hidden when a real SDL
    1.54 @@ -370,7 +394,7 @@
    1.55           * other windows when possible. */
    1.56          launchWindow.hidden = NO;
    1.57  
    1.58 -        launchWindow.rootViewController = viewcontroller;
    1.59 +        launchWindow.rootViewController = vc;
    1.60      }
    1.61  #endif
    1.62