Git Product home page Git Product logo

apigee-phonegap-push-plugin's Introduction

Apigee Push Notification Samples Featuring PhoneGap 2.X


This sample is meant to illustrate of how to integrate push into your PhoneGap based applications for PhoneGap 2.X.

###Instructions

  1. First download this repo as a .zip file.

  2. Next locate the PhoneGap push plugin for your specific version of PhoneGap.

    1. A good place to start would be here
  3. Install the plugin into your PhoneGap app

    1. If you are having trouble doing this consult the PhoneGap documentation
  4. Look in the www/js/index.js file for the PhoneGap specific implementation:


    //Listening for a push notification
    document.addEventListener('push-notification', function(event) {
        console.log('push-notification!:'+JSON.stringify(event.notification));
        navigator.notification.alert(event.notification.aps.alert);
    });

    //push registration
	var pushNotification = window.plugins.pushNotification;
    pushNotification.registerDevice({alert:true, badge:true, sound:true}, function(status) {
        //Device has been registered with push service (GCM, APNS)
    });
  1. Fill out your Apigee credentials for push notifications in their specific code.

		//Create an Apigee Client
        var client = new Apigee.Client({
            orgName:"YOUR APIGEE.COM USERNAME",
            appName:"sandbox",
            logging:true
        });
        
        //Attach PhoneGap push plugin to Window
        var pushNotification = window.plugins.pushNotification;
        //Register the device with the APNS and/or GCM
        pushNotification.registerDevice({alert:true, badge:true, sound:true}, function(status) {
        	//If a token was returned
            if(status.deviceToken) {
                //Setup device registration with Apigee
                var options = {
                	 //Alter to have your notifier name
                    notifier:"YOUR NOTIFIER",
                    deviceToken:status.deviceToken
                };
                
                //Register the actual device
                client.registerDevice(options, function(error, result){
                  if(error) {
                    console.log(error);
                  } else {
                    console.log(result);
                  }
                });
            }
        });
        
        $("#push").on("click", function(e){
            //push here
            
            //Get the devices UUID that was assigned to it from Apigee
            var devicePath = "devices/"+client.getDeviceUUID()+"/notifications";
            //Setup a push notification object
            var options = {
                //Alter to have your Notifier name
                notifier:"YOUR NOTIFIER",
                path:devicePath,
                message:"hello world from JS"
            };
            //Send the push notification to the device.
            client.sendPushToDevice(options, function(error, data){
                if(error) {
                    console.log(data);
                } else {
                    console.log("push sent");
                }
            });
        });
        
  1. Run on device or simulator. A single screen with one button should appear, and upon pressing the button a push notification should appear.

apigee-phonegap-push-plugin's People

Contributors

mdobson avatar timanglade avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

apigee-phonegap-push-plugin's Issues

client.sendPushToDevice to all devices doesn't work

I am trying to use your js example of sending push notification, but as I need to send push to all devices I changed the devicePath:
var devicePath = "devices/"+client.getDeviceUUID()+"/notifications";
to
var devicePath = "devices/*/notifications";

Calling client.sendPushToDevice then succeeds but shows Failed status in the Message History and no messages delivered. Can you please advise?

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.