仅在 iPhone 11 之后使用故事板启动后应用程序启动黑屏

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

如果我不使用启动屏幕故事板,该应用程序将 运行 在 iPhone 11 / iPhone XS Max 等上,尽管是信箱,但我不这样做想要。

当我使用启动屏幕故事板时,显示启动屏幕,然后屏幕变黑。这是它使用的代码的一部分。

 - (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;
}

你大概是运行iOS13对iPhone11?如果 运行 该应用程序在 iOS 12 或更早版本的设备上,您只需要设置主 window 和 rootViewController。用iOS13,不设置主window和rootViewController.

你应该在运行时检查这个。类似于:

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;

}

但是,为什么 运行 之前是 iPhone 11? (当您没有使用启动屏幕情节提要时,它在信箱模式下为 运行)。我怀疑这是因为,没有启动屏幕情节提要,它是 运行 兼容模式,所以不使用 iOS 13 sdk。在添加启动屏幕故事板后,它正在使用 iOS 13 sdk,您不应该设置主 window 和 rootViewController。