Skip to content

Commit

Permalink
iOS/tvOS: Try to load the launch screen as a storyboard. Xcode 8 comp…
Browse files Browse the repository at this point in the history
…iles it as a storyboard instead of a nib.
  • Loading branch information
slime73 committed Sep 25, 2016
1 parent 9165ba7 commit 666d3fe
Showing 1 changed file with 29 additions and 5 deletions.
34 changes: 29 additions & 5 deletions src/video/uikit/SDL_uikitappdelegate.m
Expand Up @@ -128,13 +128,18 @@ - (NSUInteger)supportedInterfaceOrientations;
@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. */
Expand Down Expand Up @@ -357,9 +362,28 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
* 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;

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 (viewcontroller.view) {
if (vc.view) {
launchWindow = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];

/* We don't want the launch window immediately hidden when a real SDL
Expand All @@ -370,7 +394,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
* other windows when possible. */
launchWindow.hidden = NO;

launchWindow.rootViewController = viewcontroller;
launchWindow.rootViewController = vc;
}
#endif

Expand Down

0 comments on commit 666d3fe

Please sign in to comment.