Using AutoHideSplashScreen option with PhoneGap / Cordova application

强颜欢笑 提交于 2019-12-11 03:03:22

问题


I have tried the plugin but I can't seem to figure out how to make it work with Cordova. Without the plugin navigator.splashscreen isn't defined. What am I missing?


回答1:


A plugin should not be needed.

Set the key AutoHideSplashScreen to NO in Cordova.plist, then after device ready fires, use navigator.splashscreen.hide(); to hide the splash screen.

It might be that you are not waiting till deviceready before trying to access navigator.splashscreen

edit

As mentioned by @respectTheCode below, as of 1.6 this has been removed and codified across platforms as cordova.exec(null, null, “SplashScreen”, “hide”, [])




回答2:


OK, I took RespectTheCode's advice and removed the device ready event out of the onLoad function. This is the working code. I'm putting the full code for other's who are learning:

<script>
    document.addEventListener("deviceready", onDeviceReady, false);

    setTimeout(function() {
       navigator.splashscreen.hide();
       }, 1000);
</script>

The 1000 is one second. Will not work for less than one second i.e 500. Splash screen just hangs.

This is working for me. If code could be improved, feel free to answer it and I'll bump you up.

Also, PhoneGap/Cordova has a bug where you have to use splash images at the full size of the screen (768x1024). Follow the discussion here: https://issues.apache.org/jira/browse/CB-263

Or here: How to stop iOS launch image moving up in Phonegap / Sencha Touch



来源:https://stackoverflow.com/questions/9933988/using-autohidesplashscreen-option-with-phonegap-cordova-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!