需要在 Phonegap 的 Splashscreen 中调用一个函数

Need to call a function while Splashscreen in Phonegap

我想在 phonegap 应用程序的闪屏上显示祝酒词。 toast 应与启动画面一起显示,而不是在启动画面之后显示。

有趣的问题和显示更多信息的好主意。我刚刚做了一个测试,它通过使用这个插件工作:

https://www.npmjs.com/package/cordova-plugin-splashscreen

https://www.npmjs.com/package/cordova-plugin-x-toast

在 cordova deviceready-event 之后,只需调用:

navigator.splashscreen.show();

然后你的祝酒词,这里是文档中的示例:

window.plugins.toast.showWithOptions(
            {
                message: "hey there",
                duration: "short",
                position: "bottom",
                addPixelsY: -40,  // (optional) added a negative value to move it up a bit (default 0)
                data: {} // (optional) pass in a JSON object here (it will be sent back in the success callback below)
            },
            // implement the success callback
            function(result) {
                if (result && result.event) {
                    console.log("The toast was tapped");
                    console.log("Event: " + result.event); // will be defined, with a value of "touch" when it was tapped by the user
                    console.log("Message: " + result.message); // will be equal to the message you passed in
                    console.log("data.foo: " + result.data.foo); // .. retrieve passed in data here
                } else {
                    console.log("The toast has been shown");
                }
            }
        );

最简单的方法是将 toast 代码保存在设备就绪函数中。因此,当应用程序启动时,消息将与它一起显示在启动画面上。

document.addEventListener("deviceready", onDeviceReady, false);
    function onDeviceReady() {
       // write your code here
    }