From 666d3fecc868db74b09d876ce9e8bed1ee768b32 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Sat, 24 Sep 2016 23:33:49 -0300 Subject: [PATCH] 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 | 34 ++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/src/video/uikit/SDL_uikitappdelegate.m b/src/video/uikit/SDL_uikitappdelegate.m index 98ca22359..1159b6010 100644 --- a/src/video/uikit/SDL_uikitappdelegate.m +++ b/src/video/uikit/SDL_uikitappdelegate.m @@ -128,13 +128,18 @@ SDL_LoadLaunchImageNamed(NSString *name, int screenh) @implementation SDLLaunchScreenController - (instancetype)init +{ + return [self initWithNibName:nil bundle:[NSBundle mainBundle]]; +} + +- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { if (!(self = [super initWithNibName:nil bundle:nil])) { return nil; } - NSBundle *bundle = [NSBundle mainBundle]; - NSString *screenname = [bundle objectForInfoDictionaryKey:@"UILaunchStoryboardName"]; + NSString *screenname = nibNameOrNil; + NSBundle *bundle = nibBundleOrNil; BOOL atleastiOS8 = UIKit_IsSystemVersionAtLeast(8.0); /* Launch screens were added in iOS 8. Otherwise we use launch images. */ @@ -357,9 +362,28 @@ SDL_LoadLaunchImageNamed(NSString *name, int screenh) * displayed (e.g. if resources are loaded before SDL_GL_SwapWindow is * called), so we show the launch screen programmatically until the first * time events are pumped. */ - UIViewController *viewcontroller = [[SDLLaunchScreenController alloc] init]; + UIViewController *vc = nil; - if (viewcontroller.view) { + NSString *screenname = [bundle objectForInfoDictionaryKey:@"UILaunchStoryboardName"]; + + if (screenname && UIKit_IsSystemVersionAtLeast(8.0)) { + @try { + /* The launch storyboard is actually a nib in some older versions of + * Xcode. We'll try to load it as a storyboard first, as it's more + * modern. */ + UIStoryboard *storyboard = [UIStoryboard storyboardWithName:screenname bundle:bundle]; + vc = [storyboard instantiateInitialViewController]; + } + @catch (NSException *exception) { + /* Do nothing (there's more code to execute below). */ + } + } + + if (vc == nil) { + vc = [[SDLLaunchScreenController alloc] initWithNibName:screenname bundle:bundle]; + } + + if (vc.view) { launchWindow = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; /* We don't want the launch window immediately hidden when a real SDL @@ -370,7 +394,7 @@ SDL_LoadLaunchImageNamed(NSString *name, int screenh) * other windows when possible. */ launchWindow.hidden = NO; - launchWindow.rootViewController = viewcontroller; + launchWindow.rootViewController = vc; } #endif