26 de dez. de 2016

Using Cordova Plugin without ngCordova


I needed to verify the Wifi that the app is connected and I didn´t find the Cordova plugin in ngCordova list, so I found the WifiWizard plugin that had all that I needed and used it inside the app.
Below, I put the steps that I did to get it working:

  1. ionic start WifiWizard blank
  2. cd WifiWizard
  3. ionic platform add android
  4. cordova plugin add WifiWizard
  5. ionic run android -l
One tip is to put the method call of the plugin iside a $ionicPlatform.ready(function() { }

.service('WifiService', function($ionicPlatform) { 
  var service = this; 
  $ionicPlatform.ready(function() { 
    WifiWizard.listNetworks(successNetwork, failNetwork); 
  })

   var successNetwork = function(response) { console.log("successNetwork"); } 
   var failNetwork = functionresponse { console.log("failNetwork"); } 
});


We can also call the plugin using:
window.WifiWizard.listNetworks()

Nenhum comentário: