Code Monkey home page Code Monkey logo

cordova-push-notification-'s Introduction

Cordova-Push-Notification

Push Notification

For the purpose of sending push notifications to cordova apps. The first step is to obtain a device token. A "device token" is specific to each device and each project.

Pre-requisite:

Google Cloud Messaging Project Number For this go to Google Developer Console and create a new project. Under Project Information is the Project Number

Google Cloud Messaging API Key for above Project (needed for server) Go to Library -> Google Cloud Messaging -> Enable. Go to Credentials to create an API key of Type server.

Adding the push-plugin to project:

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

SENDER_ID represents the Project Id

Place the following code inside receivedEvent function within index.js

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

push.on('registration', function(data) {
    console.log("device token: " + data.registrationId);
});

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

push.on('error', function(e) {
       console.log(e.message)
});

On running the above code from an Android or iOS device gives a device token.

NOTE: Device token shall be generated only on a real device not a virtual device.

For testing push notification go to this link [http://apns-gcm.bryantan.info/] Online Push Notification Test

For Android: Enter the Device token, Message and API key

For iOS: Enter the Device token, Message , choose PEM file and the environment (sandbox/production)

cordova-push-notification-'s People

Contributors

akash-pal avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.