iOS/tvOS: Try to load the launch screen as a storyboard. Xcode 8 compiles it as a storyboard instead of a nib.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
diff --git a/src/video/uikit/SDL_uikitappdelegate.m b/src/video/uikit/SDL_uikitappdelegate.m
index 98ca223..1159b60 100644
--- a/src/video/uikit/SDL_uikitappdelegate.m
+++ b/src/video/uikit/SDL_uikitappdelegate.m
@@ -129,12 +129,17 @@ SDL_LoadLaunchImageNamed(NSString *name, int screenh)
- (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;
+
+ 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
@@ -370,7 +394,7 @@ SDL_LoadLaunchImageNamed(NSString *name, int screenh)
* other windows when possible. */
launchWindow.hidden = NO;
- launchWindow.rootViewController = viewcontroller;
+ launchWindow.rootViewController = vc;
}
#endif