apache / cordova-ios

Apache Cordova iOS
https://cordova.apache.org/
Apache License 2.0
2.16k stars 990 forks source link

Calling `navigator.splashscreen.hide()` does not hide the splashscreen #918

Closed FireLizard closed 4 years ago

FireLizard commented 4 years ago

Bug Report

Problem

What is expected to happen?

Hiding the splashscreen by calling navigator.splashscreen.hide().

What does actually happen?

Its not hiding the splashscreen.

Information

Config

<?xml version='1.0' encoding='utf-8'?>
<widget id="..." version="...">
    <preference name="ShowSplashScreenSpinner" value="false" />
    <preference name="SplashShowOnlyFirstTime" value="false" />
    <preference name="AutoHideSplashScreen" value="false" />
</widget>

Version information

Checklist

eun-choi commented 4 years ago

Same issue. I would like to hide the splashscreen after all the features of the app have been loaded instead of AutoHideSplashScreen. If the developer has integrated splashscreen functionality, provide a way to use the show and hide functionality.

zmalter99 commented 4 years ago

According to cordova-plugin-splashscreen documentation, you can use the following code within the deviceready event handler:

document.addEventListener("deviceready", function () {
    setTimeout(function () {
        navigator.splashscreen.hide();
    }, 2000);
});

A few things to note, the AutoHideSplashScreen preference in your config.xml must be set to false (which you already did) and of course you must link the cordova.js file to your HTML document: <script src="cordova.js"></script> I've forgotten to do that before. Would you mind sharing your code if the above doesn't work?

FireLizard commented 4 years ago

I've tried that already :( Here my most minimal index.html

<!DOCTYPE html>
<html>
<head>
    <script type="text/javascript" src="cordova.js"></script>
</head>
<body>
    <script>
        document.addEventListener('deviceready', function () {
            alert('deviceready');
            setTimeout(function () {
                alert('hide now');
                navigator.splashscreen.hide();
            },4000);
        })
    </script>
</body>
</html>

Both alerts were shown, but the splashscreen stays there.

I've built it with Xcode v11.5 and testet on an iPhone 7, iOS 13.5.1.

zmalter99 commented 4 years ago

I created a test project with the code above and the splashscreen successfully faded away after four seconds from the device ready alert. Here's my code:

www/index.html

<!DOCTYPE html>
<html>
<head>
    <script type="text/javascript" src="cordova.js"></script>
</head>
<body>
    <script>
        document.addEventListener('deviceready', function () {
            alert('deviceready');
            setTimeout(function () {
                alert('hide now');
                navigator.splashscreen.hide();
            },4000);
        })
    </script>
    Content goes here...
</body>
</html>

config.xml

<?xml version="1.0" encoding="UTF-8" ?>
<widget xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0" id="com.example.app" version="1.0">
  <name>Example App</name>
  <description>N/A</description>
  <author href="http://example.com" email="app@example.com">Example App</author>

  <preference name="ShowSplashScreenSpinner" value="false" />
  <preference name="SplashShowOnlyFirstTime" value="false" />
  <preference name="AutoHideSplashScreen" value="false" />
</widget>

I then ran the following commands in the root of my project:

cordova platform add https://github.com/apache/cordova-ios/archive/6.1.0.tar.gz
cordova build ios

Edit: forgot that you don't need the cordova-plugin-splashscreen since it's added to cordova-ios since 6.0.0

FireLizard commented 4 years ago

I can not tell why but after removing an reinstalling cordova-ios and splashscreen-plugin it works now:

$ cordova platform remove ios

$ cordova plugin remove cordova-plugin-splashscreen

$ rm -rf platforms/ plugins/

$ cordova platform add ios@^6.1.0
Using cordova-fetch for cordova-ios@^6.1.0
Adding ios project...
Creating Cordova project for the iOS platform:
        Path: platforms/ios
        Package: com.example.app
        Name: My App
iOS project created with cordova-ios@6.1.0
Installing "cordova-plugin-file" for ios
Installing "cordova-plugin-whitelist" for ios

$ cordova plugin add cordova-plugin-splashscreen
Unmet project requirements for latest version of cordova-plugin-splashscreen:
    cordova-ios (6.1.0 in project, <6.0.0 required)
Current project does not satisfy the engine requirements specified by any version of cordova-plugin-splashscreen. Fetching latest version of plugin anyway (may be incompatible)
Installing "cordova-plugin-splashscreen" for ios
Plugin doesn't support this project's cordova-ios version. cordova-ios: 6.1.0, failed version requirement: <6.0.0
Skipping 'cordova-plugin-splashscreen' for ios
Adding cordova-plugin-splashscreen to package.json
brassier commented 3 years ago

For others seeing this issue, similar impacts are being noted in this issue: https://github.com/apache/cordova-plugin-splashscreen/issues/192

jptrainor commented 3 years ago

Here is the key point: "... you don't need the cordova-plugin-splashscreen since it's added to cordova-ios since 6.0.0".

Removing the old plugin fixed this for me.