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