I followed all instructions about splash screen adding to my application
but when i make the code and try to excute that in my android phone :
angular.module('starter', ['ionic', 'ngCordova' ,'starter.controllers', 'starter.services' ])
.run(function($ionicPlatform, $cordovaSplashscreen) {
window.setTimeout(function() {
try{
$cordovaSplashscreen.hide();
}catch(err){ window.alert("SplashError:" + err.message)}
}, 5000);
...
I got an error message that it cannot call “hide” method of undefined.
How fix this.
Thanks
Hey slashdreama -
In which environment is this error being generated? If you’re seeing the error within the browser, that’s expected - cordova.js isn’t provided and so Cordova plugins are not initialized (i.e. the relevant methods aren’t added to the navigator
object).
@RyanBrewtown try on Android and i test directly on my phone using $ionic run android
.
And the second point is how control splashscreen ?
thank
Try this
.run(function($ionicPlatform, $timeout) {
$ionicPlatform.ready(function() {
$timout(function(){
$cordovaSplashscreen.hide();
},5000);
});
});
Sounds like a case of needing to be wrapped around device ready
ok I’ll just try that .
but on .run(function($ionicPlatform, $timeout) {
we don’t need to add $cordovaSplashscreen as argument ? so we got this :
.run(function($ionicPlatform, $timeout, $cordovaSplashscreen) {
..
Laziness is kicking on my end…yes you do need need to include $cordovaSplashscreen
lol , i hope that this tips gone help , cauz’ i lost sleep since 3 days
Also make sure you’ve included the actual splashscreen plugin
oohh! how get the lastest version or update plugin with ionic ??
if you already the plugin added, you’ll have to remove it then add it back
$ ionic plugin rm org.apache.cordova.splashscreen
$ ionic plugin add org.apache.cordova.splashscreen
ok great i got it. thanks
I tried but the problem persist I can’t control splash screen .
so iI decided to put a alert function in $ionicPlatform.ready() but when I launch on my phone I can’t the alert showed.
$ionicPlatform.ready(function() {
window.alert('App is ready'); // it's never showed when i launch in my phone
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
if(window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
}
if(window.StatusBar) {
// org.apache.cordova.statusbar required
StatusBar.styleDefault();
}
//try{
// $cordovaSplashscreen.hide();
//}catch(err){ window.alert("SplashError on ready:" + err.message)}
});
Can you try without the try/catch syntax?
yes I did it before using try/catch but nothing.
And I remark that any action in $ionicPlatform.read(function(){ … … }); fired.
Why? I tried ionic.Platform.read(…) no result , what’s happening !!
Hmm, lets try this, just so we can rule everything out.
Lets make a test project and go over everything.
$ ionic start tmp tabs && cd tmp
$ bower install ngCordova
The add this before cordova.js
<script src="lib/ngCordova/dist/ng-cordova.js"></script>
Then include ngCordova as a dependency
angular.module('starter', ['ionic', 'ngCordova', 'starter.controllers', 'starter.services'])
.run(function($ionicPlatform, $cordovaSplashscreen, $timeout) {
$ionicPlatform.ready(function() {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
if (window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
}
// Wait 2secs before hiding splash screen
$timeout(function() {
$cordovaSplashscreen.hide();
}, 2000);
if (window.StatusBar) {
// org.apache.cordova.statusbar required
StatusBar.styleDefault();
}
});
})
2 Likes
Yes it works !!
I think that i gone completely make again my application .
So why sometime all things gone bad with ionic?
or how organize my files on my project
Well since Ionic is jus the UI, cordova is the one responsible here.
Cordova’s can be tricky and temperamental, so there is going to be a few hiccups here and there.
Another question: do you think the fact to use nested “try/catch” can be the cause of the problem ??
Could have, but its valid javascript so I’m a bit confused as to why it would cause issues.