0

I am working Cordova iOS Platform. I need to add Push Notification in my Project.

Steps:

  1. I have created a project in Google console and created a Project-ID.

  2. Created a APNS PushNotification Production Certificate from Apple Developer.

  3. Below Plugin Added in my Project

    cordova plugin add phonegap-plugin-push --variable SENDER_ID="722784892462"

In index.js

   var pushNotification; 
gcmNotification = {
  onNotificationAPN : function (e) {
      if (e.id)
      {
        navigator.notification.beep();
        
      }
  },
  registerPushNotification : function () {
     try{
      pushNotification = window.plugins.pushNotification;     

      var errorHandler = function (error) {
        console.log(error);
      };

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

      pushNotification.register(tokenHandler, errorHandler, { "badge": "true", "sound": "true", "alert": "true", "ecb": "onNotificationAPN" });

    }catch(e){
      exceptionAlert("registerPushNotification>>"+e);
    }
  }
}

function onNotificationAPN(e)
{
  gcmNotification.onNotificationAPN(e);
}

I tried in my real device.

I got the Below error:

enter image description here

Community
  • 1
  • 1
GK_
  • 1,212
  • 1
  • 12
  • 26

2 Answers2

0

Have u add cordova.js file in your html page

<script type="text/javascript" src="cordova.js"></script>
Shanmugapriya D
  • 306
  • 3
  • 13
0

I 've found the solution. I have replaced the code from PushNotification.js to Push.js

https://github.com/phonegap/phonegap-plugin-push/tree/master/www

and added the below code in index.js

var push = PushNotification.init({
    android: {
        senderID: "12345679"
    },
    ios: {
        alert: "true",
        badge: "true",
        sound: "true"
    },
    windows: {}
});

push.on('registration', function(data) {
    // data.registrationId
});

push.on('notification', function(data) {
    // data.message,
    // data.title,
    // data.count,
    // data.sound,
    // data.image,
    // data.additionalData
});

push.on('error', function(e) {
    // e.message
});
GK_
  • 1,212
  • 1
  • 12
  • 26