Showing splash screen in PhoneGap/Cordova 1.5.0 - ios

I'm trying to get my splash screen to show for my PhoneGap/Cordova native iOS app. The default or boolean for this behavior is set to 'YES'. I'm trying to get the screen to show for 2 seconds. At the moment, it only shows for a split second and then goes right into the app. Since my app does not download any data for the web on start, it loads pretty quickly.
According to this advice, this solution works for some. I'm using the latest Cordova 1.5.0 build: http://shazronatadobe.wordpress.com/2011/09/15/ios-phonegap-splash-screen-control/
I've turned the AutoHideSplashScreen to 'NO' in the Cordova.plist and I'm using this code:
function onLoad() {
document.addEventListener("deviceready", onDeviceReady, false);
}
setTimeout(function() {
navigator.splashscreen.hide();
}, 2000);
I've tried putting the setTimeout function within a function, but to no avail. Like so:
function onLoad() {
document.addEventListener("deviceready", onDeviceReady, false);
}
function hideSplash() {
setTimeout(function() {
navigator.splashscreen.hide();
}, 2000);
}
And then loading the 'hideSplash()' when the Body loads. But to no avail.
Anything wrong with my code?

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 for those who don't know. Will not work for less than one second i.e 500. Splash screen just hangs.
This is working for me when I install and app works fine,however, when I restart the device (iPad2) the splash screen hangs like the previous problem (above paragraph) and will not enter the app. Weird bug.
Anyone else experience this?
I'm on iOS 5.1 building with Xcode 4.3.1 and Cordova 1.5.0

I am using Cordova 2.1.0 and now 2.2.0.
When calling navigator.splashscreen.hide(), the Splash Screen didn't disappear.
Using the following code, it worked:
private static native void hideSplashScreen() /*-{
$wnd.Cordova.exec(null, null, "SplashScreen", "hide", []);
}-*/;
Hope this helps

Related

Splash screen prevent from hiding after ejecting expo

Recently I have ejected my project from expo to dare and do all the necessary things like pod install and all.
When I run my project Its runs fine but as soon as I click on any modal or any other button its don't show any error logs and shows Splashscreen and it's not hiding the code which should be executed in the use effect is not excuting. Sometimes it's said.
'SplashScreen.show' has already been called for given view controller.
It works well on the real device but the splash screen not hiding on the simulator.
I am stuck in for the last 3 days and do all the necessary things. Check almost all the questions on StackOverflow regarding this.
I have also try below code but it doesn't work.
import * as SplashScreen from 'expo-splash-screen';
useEffect(() => {
console.log('A');
setTimeout(async () => {
console.log('B');
await SplashScreen.hideAsync();
}, 10000);
}, []);
useEffect(async () => {
await SplashScreen.hideAsync();
}, []);
I have tried almost everything and all the things were working perfectly before ejecting;

Device Ready ios not working

I know this is repeated like ton of times but I cannot find the way to resolve it.
We have an app running in android with no problems.
But when I install it in my iphone the device ready does not get fired.
The device ready jumps in android but in ios if auto-hide-splash-screen is false it keeps stuck in the splashscreen and deviceready is not fired.
I am making the build with phonegap build.
The version of cordova is 3.7.0
the code of the device ready is
document.addEventListener('deviceready', function() {
alert('listening to device ready'+navigator);
navigator.splashscreen.hide();
}, false);
Try something like :
var onLoad = function(){
document.addEventListener("deviceready", deviceReady, false);
};
var deviceReady = function(){
document.addEventListener("backbutton", exitCordova, false);
alert('listening to device ready'+navigator);
navigator.splashscreen.hide();
};
var exitCordova = function(){
navigator.app.exitApp();
};

KendoUI mobile app, view event afterShow has no access to cordova plugin. Outside event is fine

I have a kendoui applbuilder mobile app. I have installed a custom camerapreview plugin and it works fine. I tried adding an event handler to my view (afterShow) to set something in the camera plugin module:
cordova.plugins.camerapreview.startCamera(
which initializes the camera preview.
the problem seems to be that in this handler cordova.plugins.camerapreview is undefined? Access to this same method in a button handler on the view works fine. I'm assuming this has something to do with dependency? How can i ensure this is loaded? Doesn't make sense to me that it wouldn't be available after the view has loaded and bound the model.
my code looks like:
// Handle "deviceready" event
document.addEventListener('deviceready', onDeviceReady, false);
var mobileApp = new kendo.mobile.Application(document.body, {
skin: 'flat',
initial: 'views/home.html'
});
When using Kendo UI Mobile app with Cordova, make sure to initialize the app in the deviceready event. This will ensure that the Cordova APIs will be available throughout the whole app lifecycle.
// this function is called by Cordova when the application is loaded by the device
document.addEventListener('deviceready', function () {
// hide the splash screen as soon as the app is ready. otherwise
// Cordova will wait 5 very long seconds to do it for you.
navigator.splashscreen.hide();
app = new kendo.mobile.Application(document.body, {
// you can change the default transition (slide, zoom or fade)
transition: 'slide',
// comment out the following line to get a UI which matches the look
// and feel of the operating system
// skin: 'flat',
// the application needs to know which view to load first
initial: 'views/home.html'
});
}, false);

Phonegap-Blackberry backpress issue/how to handle back key in phonegap

when i pressed back key using blackberry simulator then its close my whole application but when i pressed back button which i provided in header then its working fine.how to solved this is? is there any backpress handing in phonegap? Same code for android works fine means it doesn't close application on back key press.
Or
<script type="text/javascript">
// Wait for PhoneGap to load
//
document.addEventListener("deviceready", onDeviceReady, false);
// PhoneGap is ready
//
function onDeviceReady() {
blackberry.system.event.onHardwareKey(blackberry.system.event.KEY_BACK,
function() {
history.back();
return false;
});
}
</script>
On config.xml --> <feature id="blackberry.system.event" version="1.0.0"/>

PhoneGap navigator.compass.getCurrentHeading called multiple times on iPhone

I would appreciate any help in solving this - or at least where to look to solve it.
What I have is calling on iPhone navigator.compass.getCurrentHeading(succ, fail), the success function is called every time the device is moved even slighly. In the XCode debug log I see lots of entries of navigator.compass.setHeading calls being generated for every movement. If I try to poll for heading data again - the request just hangs. Here's the code:
function onBodyLoad() {
if (typeof navigator.device == "undefined") {
document.addEventListener("deviceready", onDeviceReady, false);
} else {
onDeviceReady();
}
}
function succ(heading) {
alert("compass " + heading);
}
function fail() {
alert('fail');
}
function onDeviceReady() {
navigator.compass.getCurrentHeading(succ, fail);
}
This is really strange behaviour, as I expect getCurrentHeading to be called just once and return a single result, instead of the unstoppable flurry of events.
I use PhoneGap 1.0.0. The same code on Android works perfectly. I've removed all custom JS code to prevent possibility of conflicts.
It is odd that noone else seems to encounter this. In any case, this (hacky) solution may help anyone who comes looking for an answer.
We had to stop using getCurrentHeading because of this issue, and replaced it with navigator.compass.watchHeading instead. On clearing the watch we also call navigator.compass.stop() function to prevent from further compass spamming (for iPhone platform only - Android is fine), and before calling watchHeading again we call navigator.compass.stop() and navigator.compass.start(), to reinitialize the compass "just in case" (again, on iPhone only).
After taking these measures the page that user compass no longer hangs on second entry, and there is no heading spamming outside of this page.

Resources