ionic-framework icon indicating copy to clipboard operation
ionic-framework copied to clipboard

bug: Launch freeze/crash on manual splash screen hiding

Open zarko-tg opened this issue 10 years ago • 79 comments

Type: bug

Ionic Version: 1.x

Platform: ios 9 webview

Experiencing a rather critical issue since getting on Cordova 6.0.0 for iOS. We have a scenario where we hide the Cordova splash screen manually relatively shortly after app launch. The problem is that quite often during launch the app just stays on the splash screen instead of continuing after hiding it, and eventually crashes. It looks like some sort of race condition at least from a user perspective.

Some testing shows with a good certainty that:

  • Cordova 5.4.1 does not manifest the problem.
  • Removing the cordova-plugin-device from the test app makes the problem disappear.
  • I cannot reproduce in a pure Cordova app (without Ionic & Angular).
  • In case the freeze doesn't occur, try killing the app and the starting it again - at one attempt or another it will come to a halt.
  • Android is not a problem.
  • Experiencing on both simulator and device, and both iOS 8.4.x and 9.x.
  • Console / system logs don't appear to show anything useful or relevant.

Use a cordova-plugin-splashscreen from its latest Github master branch since its latest "stable" version 3.1.0 has a bug related to the AutoHideSplashScreen config.xml parameter.

This might just be a pure Cordova core or plugins bug but as said - so far I haven't been able to trigger it with an app that doesn't use Ionic.

My system information:

Cordova CLI: 6.0.0 Gulp version: CLI version 3.9.0 Gulp local:
Ionic Version: 1.2.4 Ionic CLI Version: 1.7.14 Ionic App Lib Version: 0.7.0 ios-deploy version: 1.8.4 ios-sim version: 5.0.6 OS: Mac OS X El Capitan Node Version: v4.2.4 Xcode version: Xcode 7.2.1 Build version 7C1002

cordova-ios 4.0.1

zarko-tg avatar Feb 03 '16 21:02 zarko-tg

Download a demo app here: http://1drv.ms/20rf9fu

  • Make sure you have Cordova 6.0.0 installed
  • Run ionic platform add ios
  • Run ionic emulate ios

Start the app and see the splash screen not go away when it should. If it does go away, kill the app and start it again. Repeat until reproduced.

zarko-tg avatar Feb 03 '16 22:02 zarko-tg

@mhartington Please have someone look at this to at least reproduce and get the case going. I will also write on the Cordova Dev mailing list.

zarko-tg avatar Feb 03 '16 22:02 zarko-tg

As said, personally I wasn't able to reproduce without Ionic. But maybe someone will. In such a case we can close the case here and move it in Cordova's Jira.

zarko-tg avatar Feb 03 '16 22:02 zarko-tg

try with the latest version of the splash plugin on github that has the AutoHideSplashScreen problem fixed

jcesarmobile avatar Feb 03 '16 22:02 jcesarmobile

@jcesarmobile I know. But this problem occurs with a plugin version from the latest master. See the config.xml in the demo app (ionicSplash.zip).

zarko-tg avatar Feb 03 '16 22:02 zarko-tg

cc @daserge

zarko-tg avatar Feb 03 '16 22:02 zarko-tg

Ok so I've been able to replicate this but it's very hit and miss. I see it once, kill the process, and it works fine again. But I haven't been able to pin point the exact cause of it yet

mhartington avatar Feb 03 '16 22:02 mhartington

@mhartington If you clone https://github.com/rossholdway/ionic-ios-cordova-bug and run that on an actual device the 'freeze' frequently occurs. (manually booting angular seems to cause it a lot, maybe some sort of race condition).

rossholdway avatar Feb 03 '16 22:02 rossholdway

Now check this out Mike: Remove the device plugin from the config, then ionic state clear, ionic platform add ios and ionic emulate ios. I tried pretty hard to reproduce in such a case but the problem oddly disappeared.

zarko-tg avatar Feb 03 '16 22:02 zarko-tg

I mean, try it with the latest version of the splash plugin on github that has the AutoHideSplashScreen problem fixed, because maybe your issue is fixed too, just to confirm.

jcesarmobile avatar Feb 03 '16 23:02 jcesarmobile

@jcesarmobile I'm pulling the plugin right from github and can see it

mhartington avatar Feb 03 '16 23:02 mhartington

@jcesarmobile not sure how to make myself anymore clearer. I do use the latest version from master, not 3.1.0.

zarko-tg avatar Feb 03 '16 23:02 zarko-tg

Okay so some update information So when the splashscreen does fail, it's still logging out Calling navigator.splashscreen.hide.

mhartington avatar Feb 03 '16 23:02 mhartington

Still very hit and miss, but this does seem like a race condition

@zarko-tg and @rossholdway, can you try this out in our demos?

.run(function($ionicPlatform) {
  $ionicPlatform.ready(function() {
    console.log('Calling splashscreen hide');
  }).then(function(){
    navigator.splashscreen.hide();
  });
})

mhartington avatar Feb 03 '16 23:02 mhartington

@mhartington true. Other than that, if you wrap the hide call for example with a setTimeout of couple of seconds, the problem will be gone. I thus suspect some race condition in Cordova, Ionic/Angular or in relation to one another. I had a hard time scratching my head today. A blocker for moving onto Cordova 6.0.0 in our case.

zarko-tg avatar Feb 03 '16 23:02 zarko-tg

@mhartington first thing tomorrow. I'm still on Windows at home for some reason.

zarko-tg avatar Feb 03 '16 23:02 zarko-tg

There's some work-arounds right now, like moving that splashscreen.hide call into the .then, which will wait until the promise is resolved. Will look into this tomorrow

mhartington avatar Feb 03 '16 23:02 mhartington

I'm not sure my issue #5318 is related to the splash screen... The app sometimes freezes for me before the console.log can output anything.

rossholdway avatar Feb 03 '16 23:02 rossholdway

Hi guys, Investigating this issue - indeed repros only on Cordova 6.0.0 + [email protected]. It in fact repros with [email protected] as well after fixing AssetCatalog image paths:

    // Add Asset Catalog specific prefixes
    if ([imageName isEqualToString:@"LaunchImage"])
    {
        if (device.iPhone4 || device.iPhone5 || device.iPad) {
            imageName = [imageName stringByAppendingString:@"-700"];
        } else if(device.iPhone6) {
            imageName = [imageName stringByAppendingString:@"-800"];
        } else if(device.iPhone6Plus) {
            imageName = [imageName stringByAppendingString:@"-800"];
            if (currentOrientation == UIInterfaceOrientationPortrait || currentOrientation == UIInterfaceOrientationPortraitUpsideDown)
            {
                imageName = [imageName stringByAppendingString:@"-Portrait"];
            }
        }
    }

Otherwise the splashscreen will not even show because of the image could not be found: WARNING: The splashscreen image named LaunchImage-736h was not found

daserge avatar Feb 04 '16 09:02 daserge

@mhartington making the call to navigator.splashscreen.hide after $ionicPlatform.ready resolved does not make a big difference as it is stil possible to reproduce. However, the mystery deepened even further after some more testing with the following code:

.run(function($ionicPlatform) {
  var t = performance.now();
  console.log('Calling $ionicPlatform.ready');

  $ionicPlatform.ready(function() {
    console.log('$ionicPlatform.ready took ' + (performance.now() - t) + ' ms.');
    t = performance.now();
  }).then(function() {
    console.log(
      '$ionicPlatform.ready resolve took ' + (performance.now() - t) + ' ms. '
        + 'Calling navigator.splashscreen.hide'
    );
    navigator.splashscreen.hide();
    console.log('navigator.splashscreen.hide called');
  });
})

when ran on my iPhone 6 (with iOS 9.3 13E5191d).

Here's some of the log output taken using idevicesyslog | grep ionicSplash:

09:50:13 ... [8032] <Warning>: Apache Cordova native platform version 4.0.1 is starting.
09:50:13 ... [8032] <Warning>: Multi-tasking -> Device: YES, App: YES
09:50:13 ... [8032] <Warning>: Using UIWebView
09:50:14 ... [8032] <Warning>: [CDVTimer][handleopenurl] 0.186980ms
09:50:14 ... [8032] <Warning>: Unlimited access to network resources
09:50:14 ... [8032] <Warning>: [CDVTimer][intentandnavigationfilter] 2.368987ms
09:50:14 ... [8032] <Warning>: [CDVTimer][gesturehandler] 0.154018ms
09:50:14 ... [8032] <Warning>: [CDVTimer][splashscreen] 40.008008ms
09:50:14 ... [8032] <Warning>: [CDVTimer][TotalPluginStartup] 43.819964ms
09:50:14 ... [8032] <Warning>: Resetting plugins due to page load.
09:50:14 ... [8032] <Error>: Ring Logging is disabled
09:50:14 ... [8032] <Warning>: Finished load of: file:///var/containers/Bundle/Application/4DFB0B3A-EB6A-4E07-A0BD-659487998B37/.app/www/index.html#/tab/dash
09:50:14 ... [8032] <Warning>: $ionicPlatform.ready took 347.33000000000004 ms.
09:50:14 ... [8032] <Warning>: $ionicPlatform.ready resolve took 17.029999999999973 ms. Calling navigator.splashscreen.hide
09:50:14 ... [8032] <Warning>: navigator.splashscreen.hide called
09:50:41 ... [8033] <Warning>: Apache Cordova native platform version 4.0.1 is starting.
09:50:41 ... [8033] <Warning>: Multi-tasking -> Device: YES, App: YES
09:50:41 ... [8033] <Warning>: Using UIWebView
09:50:41 ... [8033] <Warning>: [CDVTimer][handleopenurl] 0.126004ms
09:50:41 ... [8033] <Warning>: Unlimited access to network resources
09:50:41 ... [8033] <Warning>: [CDVTimer][intentandnavigationfilter] 2.272010ms
09:50:41 ... [8033] <Warning>: [CDVTimer][gesturehandler] 0.154972ms
09:50:41 ... [8033] <Warning>: [CDVTimer][splashscreen] 40.107012ms
09:50:41 ... [8033] <Warning>: [CDVTimer][TotalPluginStartup] 43.406010ms
09:50:41 ... [8033] <Warning>: Resetting plugins due to page load.
09:50:41 ... [8033] <Error>: Ring Logging is disabled
09:50:42 ... [8033] <Warning>: Finished load of: file:///var/containers/Bundle/Application/4DFB0B3A-EB6A-4E07-A0BD-659487998B37/.app/www/index.html#/tab/dash

As you can see, the first attempt until 09:50:41 goes well. (In meantime I kill the app and start it again at 09:50:41). If the log is to be trusted, not even the callback of Angular's run gets executed.

And here comes the fun part - I decided to just set AutoHideSplashScreen to true and comment out navigator.splashscreen.hide(); in the code above. At some attempt after killing the app and starting it, the spash screen would get auto-hidden as expected but the app (UI) would become unresponsive and eventually crash. Again, the logger didn't indicate that anything was executed in the callback of Angular's run method.

So @rossholdway could be right.

zarko-tg avatar Feb 04 '16 09:02 zarko-tg