Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to implement push notification plugin in phonegap

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 546
    Comment on it

    Push notification plugin supports receiving notification in your phonegap application. It can also handle the notifications received. It supports multiple platforms like android, iOS, windows.

    Installing the Plugin:

    You have to run the following command to get the plugin in your project:

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

    or

    cordova plugin add https://github.com/phonegap/phonegap-plugin-push --variable SENDER_ID="XXXXXXX"

    here, sender id value is the project number that you have to create in your google developer console. If your application is not for android, you can give any value on this.

    You may need to add the following code in your package.json file, if you are using ionic:

    "cordovaPlugins": [
        {
          "variables": {
            "SENDER_ID": "XXXXXXX"
          },
          "locator": "phonegap-plugin-push"
        }
      ]

    There are some android requirements that you need to check to run this plugin in android:

    • Android Support Library version 23 or greater
    • Local Maven repository for Support Libraries (formerly Android Support Repository) version 20 or greater
    • Google Play Services version 27 or greater
    • Google Repository version 22 or greater

    For iOS, it requires Xcode version 7.0 or greater and cordova-ios 4 or greater.

    After installing the plugin successfully you can run the following code when your app starts to get the notification.

    Example:

    var push = PushNotification.init({
        android: {
            senderID: "12345679" //your project number
        },
        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
    });
    
    

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: