0
votes

I'm building a Cordova project with Netbeans, that uses PushPlugin (https://github.com/phonegap-build/PushPlugin).

It works great on Android, but on iOS it doesn't register the device. It also doesn't give any errors.

What's also strange is that the plugin folder (com.phonegap.plugins.PushPlugin) is in the projects /plugins folder, but it's not being copied to platforms/ios/[appname]/Plugins on build.

I have this in my config.xml:

<feature name="PushPlugin">
  <param name="android-package" value="com.plugin.gcm.PushPlugin"/>
  <param name="ios-package" value="PushPlugin"/>
</feature>

And I work with the following JavaScript:

var pushNotification;

function onDeviceReady() {
  alert('ready');
  try {
    pushNotification = window.plugins.pushNotification;
    if (typeof device == 'undefined') {
      alert('device undefined');
    }
    if (device.platform == 'android' || device.platform == 'Android' || device.platform == 'amazon-fireos') {
      pushNotification.register(successHandler, errorHandler, {
        "senderID": "[senderid]",
        "ecb": "onNotification"
      });
    } else {
      alert('ios!');
      pushNotification.register(tokenHandler, errorHandler, {
        "badge": "true",
        "sound": "true",
        "alert": "true",
        "ecb": "onNotificationAPN"
      });
    }
  } catch (err) {
    txt = "There was an error on this page.\n\n";
    txt += "Error description: " + err.message + "\n\n";
    alert(txt);
  }
}


function onNotificationAPN(e) {
  // handles APNS notifications for iOS
  if (e.alert) {
    navigator.notification.alert(e.alert);
  }
  if (e.sound) {
    var snd = new Media(e.sound);
    snd.play();
  }
  if (e.badge) {
    pushNotification.setApplicationIconBadgeNumber(successHandler, e.badge);
  }
}

function onNotification(e) {
  //handles notifications for Android (left out)
}

function tokenHandler(result) {
  alert('device token = ' + result);
}

function successHandler(result) {
  alert('success = ' + result);
}

function errorHandler(error) {
  alert('error = ' + error);
}

document.addEventListener('deviceready', onDeviceReady, false);

I do see the 'ready' and 'ios!' alerts, but after that, nothing happens.

1

1 Answers

0
votes

Problem solved! Turns out I had to copy the Plugin files and manually add them to the xcode project.