Thiago Braga
Thiago Braga

Reputation: 129

Ionic StatusBar undefined. Default is coming light

I am trying to get the default StatusBar which is black, but it's coming light. When I try to set as black the error is Uncaught ReferenceError: StatusBar is not defined including the plugin on https://github.com/apache/cordova-plugin-statusbar.git. I removed and added several times, but the StatusBar is still light.

cordova-plugin-console 1.0.2 "Console"
cordova-plugin-device 1.1.1 "Device"
cordova-plugin-file 4.1.0 "File"
cordova-plugin-media 2.1.0 "Media"
cordova-plugin-splashscreen 3.1.0 "Splashscreen"
cordova-plugin-statusbar 2.1.0 "StatusBar"
cordova-plugin-vibration 2.1.0 "Vibration"
cordova-plugin-whitelist 1.2.1 "Whitelist"
ionic-plugin-keyboard 1.0.8 "Keyboard"

The code is:

console.log(StatusBar);
if (window.StatusBar) {
  // org.apache.cordova.statusbar required
  StatusBar.styleDefault();
}

Upvotes: 0

Views: 1123

Answers (2)

Iso
Iso

Reputation: 3238

You need to wait for the deviceready event to be able to use Cordova plugins.

The simplest way to do this would be to wrap your code in a ionic.Platform.ready() call, like this:

ionic.Platform.ready(function() {
  if (window.StatusBar) {
    // org.apache.cordova.statusbar required
    StatusBar.styleDefault();
  }
});

Upvotes: 2

Nadeem Khoury
Nadeem Khoury

Reputation: 937

I faced exactly the same problem.

  1. just delete the platform,
  2. and delete all plugins.
  3. clean your project
  4. then add your plugins again,
  5. then add the platform again.
  6. compile and run.

ensure also that you delete manually the plugins folder from your projects after deleting you plugins using cordova plugin rm <PLUGIN NAME>.

Tell me if it worked with you. Happy Coding.

Upvotes: 1

Related Questions