Search code examples
ioscordovasplash-screenlaunchimage

Cordova iOS launch image changes while app is loading


I have set up my launch images / splashscreen in the Resources/splash folder with the normal naming scheme (Default~ipad.png, Default-Portrait@2x~ipad.png, etc). I have not set any of the UILaunchImage* plist entries.

When I launch my Cordova app on an iPad2, it immediately loads one of my launch images. A few seconds later (when the org.apache.cordova.splashscreen plugin starts getting run, from what I can see in the log), the launch image will change, typically to something that's a different resolution, so the entire image shifts. After that point, the image stays as it is until I call navigator.splashscreen.hide(). This has also happened on an iPhone4.

Again, the splash screen displays immediately on app open, shifts a few seconds later, the page finishes loading (according to the console) about 5 seconds in, and then navigator.splashscreen.hide() gets calls in my ready() event.

It seems to me that maybe Xcode is choosing one of my images to be the launch image by default, and then the cordova splashscreen plugin is choosing another one when it gets loaded with the other plugins. I did initially gets a black flash and a console error of "Default.png" could not be found, so I added a "Default~ipad.png" to the splash images. I had thought it would have used either the Portrait or Landscape images for ipad, but the plugin appears to only do that if CDV_IsIPad() and isOrientationLocked.

I even tried reverting all images in Resources/splash to the default Cordova launch images. When I do that, the Cordova launch image displays immediately on app load, a few seconds later, when the Cordova splashscreen plugin loads, the launch image changes to one of MY launch images, then fades on navigator.splashscreen.hide(). When this happens, I can not find any references anywhere to my launch images that I removed from the project; not in Resources/splash or in the plist. Very odd.

Any ideas why the splash screen is getting changed by the cordova splashscreen plugin, or what I should be doing to fix this?


Solution

  • I ended up looking at the pull requests for the Cordova Splashscreen plugin, just to see if anyone had addressed this issue. Looks like they did!

    in src/ios/CDVSplashScreen.m:

    - } else if (CDV_IsIPad() && isOrientationLocked) {
    -        switch (orientation) {
    -            case UIInterfaceOrientationLandscapeLeft:
    -            case UIInterfaceOrientationLandscapeRight:
    -                imageName = [imageName stringByAppendingString:@"-Landscape"];
    -                break;
    -
    -            case UIInterfaceOrientationPortrait:
    -            case UIInterfaceOrientationPortraitUpsideDown:
    -            default:
    -                imageName = [imageName stringByAppendingString:@"-Portrait"];
    -                break;
    

    should be

    +    } else if (CDV_IsIPad()) {
    +        if (isOrientationLocked) {
    +            imageName = [imageName stringByAppendingString:(supportsLandscape ? @"-Landscape" : @"-Portrait")];
    +        } else {
    +            switch (orientation) {
    +                case UIInterfaceOrientationLandscapeLeft:
    +                case UIInterfaceOrientationLandscapeRight:
    +                    imageName = [imageName stringByAppendingString:@"-Landscape"];
    +                    break;
    +
    +                case UIInterfaceOrientationPortrait:
    +                case UIInterfaceOrientationPortraitUpsideDown:
    +                default:
    +                    imageName = [imageName stringByAppendingString:@"-Portrait"];
    +                    break;
    +            }