Black screen on app launch AFTER using storyboard launch only on iPhone 11 onwards

153 views Asked by At

If I do not use a launch screen storyboard, the app will run on the iPhone 11 / iPhone XS Max, etc., albeit letterboxed, which I do not want.

When I use a launch screen storyboard, the launch screen shows, then the screen goes black. This is part of the code that it uses.

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Init the window
    window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    if( ! [CCDirector setDirectorType:kCCDirectorTypeDisplayLink] )
        [CCDirector setDirectorType:kCCDirectorTypeDefault];

    CCDirector *director = [CCDirector sharedDirector];

    // Init the View Controller
    viewController = [[RootViewController alloc] initWithNibName:nil bundle:nil];
    viewController.wantsFullScreenLayout = YES;
       // Set RootViewController to window
       self.window.rootViewController = viewController;
    EAGLView *glView = [EAGLView viewWithFrame:[window bounds]
                                   pixelFormat:kEAGLColorFormatRGB565   // kEAGLColorFormatRGBA8
                                   depthFormat:0                        // GL_DEPTH_COMPONENT16_OES
                        ];

    // attach the openglView to the director
    [director setOpenGLView:glView];

    if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
    {
        //  // Enables High Res mode (Retina Display) on iPhone 4 and maintains low res on all other devices
        if( ! [director enableRetinaDisplay:YES] )
            CCLOG(@"Retina Display Not supported");

    }

#if GAME_AUTOROTATION == kGameAutorotationUIViewController
    [director setDeviceOrientation:kCCDeviceOrientationPortrait];
#else
    [director setDeviceOrientation:kCCDeviceOrientationLandscapeLeft];
#endif

    [director setAnimationInterval:1.0/60];
    // make the OpenGLView a child of the view controller
    [viewController setView:glView];
    // make the View Controller a child of the main window
    [window addSubview: viewController.view];
    [window makeKeyAndVisible];

    // Default texture format for PNG/BMP/TIFF/JPEG/GIF images
    // It can be RGBA8888, RGBA4444, RGB5_A1, RGB565
    // You can change anytime.
    [CCTexture2D setDefaultAlphaPixelFormat:kCCTexture2DPixelFormat_RGBA8888];
    // Removes the startup flicker
    [self removeStartupFlicker];
    self.window.rootViewController = self.viewController;
    // Run the intro Scene
    [[CCDirector sharedDirector] runWithScene: [MainMenuScene scene]];


    return YES;
}
1

There are 1 answers

0
auspicious99 On BEST ANSWER

You are probably running iOS 13 on the iPhone 11? You need only set up the main window and the rootViewController if running the app on a device with iOS 12 or earlier. With iOS 13, do not set up the main window and rootViewController.

You should check this at runtime. Something like:

if (@available(iOS 13, *)) {
    // don't set up main window and rootViewController

} else {  // iOS 12 and below

    // Init the window
    window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    // Init the View Controller
    viewController = [[RootViewController alloc] initWithNibName:nil bundle:nil];
    viewController.wantsFullScreenLayout = YES;

    // Set RootViewController to window
    self.window.rootViewController = viewController;

}

But then, why was it running before on the iPhone 11? (when you did not use a launch screen storyboard, and it was running in letterboxed mode). I suspect that is because, without a launch screen storyboard, it was running in compatibility mode, so not using the iOS 13 sdk. And after you added the launch screen storyboard, then it is using the iOS 13 sdk, and you should not be setting up the main window and rootViewController.