Trouble With $cordovaPush


#1

I’m trying to get push notifications working with $cordovaPush but when I run the register function nothing happen on the device.

I have the pushPlugin installed:

 $ ionic plugin
 com.ionic.keyboard 1.0.3 "Keyboard"
 com.phonegap.plugins.PushPlugin 2.4.0 "PushPlugin"
 org.apache.cordova.console 0.2.11 "Console"
 org.apache.cordova.device 0.2.12 "Device"
 org.apache.cordova.dialogs 0.2.10 "Notification"
 org.apache.cordova.inappbrowser 0.5.2 "InAppBrowser"
 org.apache.cordova.statusbar 0.1.8 "StatusBar"

and I’m referencing the full ng-cordova.js file in my index.html

<script src="lib/ionic/js/ionic.bundle.js"></script>
<script src="js/ng-cordova.js"></script>

I have a button in my app that allows users to register the device and it’s tied to a controller function:

$scope.registerDevice = function(){
    var iosConfig = {
        "badge":"true",
        "sound":"true",
        "alert":"true"
   };
   
   alert('registerDevice');
   $cordovaPush.register(config).then(function(result) {
        alert(result);       
   }, function(err) {
        alert('Unable to register');
    });
}

Right now I get the ‘registerDevice’ alert but not the result alert. To troubleshoot this I added an alert(typeof $cordovaPush.register) and it shows ‘function’ so I’m guessing the factory is correct.

I also tried adding alerts to the factory:

.factory('$cordovaPush', ['$q', '$window', '$rootScope', function ($q, $window, $rootScope) {
  alert('cordovaPush factory..');
  return {
    // snip ...
    register: function (config) {
      alert('inside register');
      //snip

I get the ‘cordovaPush factory…’ alert when the app launches but I never get the ‘inside register’ alert.

Any ideas?


#2

should be
$cordovaPush.register(iosConfig).then(function(result) {