Commit b54a2e43 authored by Bob Easterday's avatar Bob Easterday
Browse files

initial implementation

parent e6741a0e
Loading
Loading
Loading
Loading

Example/beep.wav

0 → 100644
+11.1 KiB

File added.

No diff preview for this file type.

Example/index.html

0 → 100755
+96 −0
Changes for Example/index.html: 96 added lines, 0 removed lines.
Original line number Diff line number Diff line
<!DOCTYPE HTML>
<html>
    <head>
        <title>com.PhoneGap.c2dm</title>
        <script type="text/javascript" charset="utf-8" src="cordova-2.1.0.js"></script>
        <script type="text/javascript" charset="utf-8" src="jquery_1.5.2.min.js"></script>
        <script type="text/javascript" src="PushNotification.js"></script>
        
        <script type="text/javascript">
            var pushNotification;
            
            function onLoad() {
                document.addEventListener('deviceready', onDeviceReady, true);
            }
            
            function onDeviceReady() {
                $("#app-status-ul").append('<li>deviceready event received</li>');
                
                pushNotification = window.plugins.pushNotification;
                if (device.platform == 'android' || device.platform == 'Android') {
                    pushNotification.register(successHandler, errorHandler, {"senderID":"661780372179","ecb":"onNotificationGCM"});
                } else {
                    pushNotification.register(tokenHandler, errorHandler, {"badge":"true","sound":"true","alert":"true","ecb":"onNotificationAPN"});
                }
            }
            
            // handle APNS notifications for iOS
            function onNotificationAPN(event) {
                if (event.alert) {
                    $("#app-status-ul").append('<li>push-notification: ' + event.alert + '</li>');
                    navigator.notification.alert(event.alert);
                }
                
                if (event.sound) {
                    var snd = new Media(event.sound);
                    snd.play();
                }
                
                if (event.badge) {
                    pushNotification.setApplicationIconBadgeNumber(successHandler, event.badge);
                }
            }
            
            // handle GCM notifications for Android
            function onNotificationGCM(e) {
                $("#app-status-ul").append('<li>EVENT -> RECEIVED:' + e.event + '</li>');
                
                switch( e.event )
                {
                    case 'registered':
					if ( e.regid.length > 0 )
					{
						$("#app-status-ul").append('<li>REGISTERED -> REGID:' + e.regid + "</li>");
						// Your GCM push server needs to know the regID before it can push to this device
						// here is where you might want to send it the regID for later use.
					}
                    break;
                    
                    case 'message':
					$("#app-status-ul").append('<li>MESSAGE -> MSG: ' + e.message + '</li>');
					$("#app-status-ul").append('<li>MESSAGE -> MSGCNT: ' + e.msgcnt + '</li>');
                    break;
                    
                    case 'error':
					$("#app-status-ul").append('<li>ERROR -> MSG:' + e.msg + '</li>');
                    break;
                    
                    default:
					$("#app-status-ul").append('<li>EVENT -> Unknown, an event was received and we do not know what it is</li>');
                    break;
                }
            }
            
            function tokenHandler (result) {
                $("#app-status-ul").append('<li>token: '+ result +'</li>');
                // Your iOS push server needs to know the token before it can push to this device
                // here is where you might want to send it the token for later use.
            }
			
            function successHandler (result) {
                $("#app-status-ul").append('<li>success:'+ result +'</li>');
            }
            
            function errorHandler (error) {
                $("#app-status-ul").append('<li>error:'+ error +'</li>');
            }
            </script>
    </head>
    <body onload="onLoad();">
        <div id="app-status-div">
            <ul id="app-status-ul">
                <li>Cordova Google Cloud Messaging Plugin Demo</li>
            </ul>
        </div>
    </body>
</html>
 No newline at end of file
+16 −0

File added.

Preview size limit exceeded, changes collapsed.

Example/pushAPNS.rb

0 → 100644
+12 −0
Changes for Example/pushAPNS.rb: 12 added lines, 0 removed lines.
Original line number Diff line number Diff line
require 'rubygems'
require 'pushmeup'


APNS.host = 'gateway.sandbox.push.apple.com' 
APNS.port = 2195 
APNS.pem  = '</path/to/my/certificate/ck.pem>'
APNS.pass = '<myCertificatePassword>'

device_token = '<device token gleaned from xcode console>'
# APNS.send_notification(device_token, 'Hello iPhone!' )
APNS.send_notification(device_token, :alert => 'PushPlugin works!!', :badge => 1, :sound => 'beep.wav')

Example/pushGCM.rb

0 → 100644
+8 −0
Changes for Example/pushGCM.rb: 8 added lines, 0 removed lines.
Original line number Diff line number Diff line
require 'rubygems'
require 'pushmeup'
GCM.host = 'https://android.googleapis.com/gcm/send'
GCM.format = :json
GCM.key = "AIzaSyB9bWG4OL5-m0eSE5PYaOhsE4lvKwpWBeg"
destination = ["APA91bHi2_juaN9NMBn8bh2rzC-VTg47E8DckJzxVyVr8zxOHI-IswZZibeyyNQo6Wj9u7XVHs_eizoILByPODGtYo71O0qjGaqOoloq6fRBc8DyhQCR1KmZY6qOlUJAKqE21pD5VGN9"]
data = {:message => "this is a test", :msgcnt => "1"}
GCM.send_notification( destination, data)
Loading