Skip to content

Commit b54a2e4

Browse files
committed
initial implementation
1 parent e6741a0 commit b54a2e4

19 files changed

+2029
-3
lines changed

Example/beep.wav

11.1 KB
Binary file not shown.

Example/index.html

+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
<!DOCTYPE HTML>
2+
<html>
3+
<head>
4+
<title>com.PhoneGap.c2dm</title>
5+
<script type="text/javascript" charset="utf-8" src="cordova-2.1.0.js"></script>
6+
<script type="text/javascript" charset="utf-8" src="jquery_1.5.2.min.js"></script>
7+
<script type="text/javascript" src="PushNotification.js"></script>
8+
9+
<script type="text/javascript">
10+
var pushNotification;
11+
12+
function onLoad() {
13+
document.addEventListener('deviceready', onDeviceReady, true);
14+
}
15+
16+
function onDeviceReady() {
17+
$("#app-status-ul").append('<li>deviceready event received</li>');
18+
19+
pushNotification = window.plugins.pushNotification;
20+
if (device.platform == 'android' || device.platform == 'Android') {
21+
pushNotification.register(successHandler, errorHandler, {"senderID":"661780372179","ecb":"onNotificationGCM"});
22+
} else {
23+
pushNotification.register(tokenHandler, errorHandler, {"badge":"true","sound":"true","alert":"true","ecb":"onNotificationAPN"});
24+
}
25+
}
26+
27+
// handle APNS notifications for iOS
28+
function onNotificationAPN(event) {
29+
if (event.alert) {
30+
$("#app-status-ul").append('<li>push-notification: ' + event.alert + '</li>');
31+
navigator.notification.alert(event.alert);
32+
}
33+
34+
if (event.sound) {
35+
var snd = new Media(event.sound);
36+
snd.play();
37+
}
38+
39+
if (event.badge) {
40+
pushNotification.setApplicationIconBadgeNumber(successHandler, event.badge);
41+
}
42+
}
43+
44+
// handle GCM notifications for Android
45+
function onNotificationGCM(e) {
46+
$("#app-status-ul").append('<li>EVENT -> RECEIVED:' + e.event + '</li>');
47+
48+
switch( e.event )
49+
{
50+
case 'registered':
51+
if ( e.regid.length > 0 )
52+
{
53+
$("#app-status-ul").append('<li>REGISTERED -> REGID:' + e.regid + "</li>");
54+
// Your GCM push server needs to know the regID before it can push to this device
55+
// here is where you might want to send it the regID for later use.
56+
}
57+
break;
58+
59+
case 'message':
60+
$("#app-status-ul").append('<li>MESSAGE -> MSG: ' + e.message + '</li>');
61+
$("#app-status-ul").append('<li>MESSAGE -> MSGCNT: ' + e.msgcnt + '</li>');
62+
break;
63+
64+
case 'error':
65+
$("#app-status-ul").append('<li>ERROR -> MSG:' + e.msg + '</li>');
66+
break;
67+
68+
default:
69+
$("#app-status-ul").append('<li>EVENT -> Unknown, an event was received and we do not know what it is</li>');
70+
break;
71+
}
72+
}
73+
74+
function tokenHandler (result) {
75+
$("#app-status-ul").append('<li>token: '+ result +'</li>');
76+
// Your iOS push server needs to know the token before it can push to this device
77+
// here is where you might want to send it the token for later use.
78+
}
79+
80+
function successHandler (result) {
81+
$("#app-status-ul").append('<li>success:'+ result +'</li>');
82+
}
83+
84+
function errorHandler (error) {
85+
$("#app-status-ul").append('<li>error:'+ error +'</li>');
86+
}
87+
</script>
88+
</head>
89+
<body onload="onLoad();">
90+
<div id="app-status-div">
91+
<ul id="app-status-ul">
92+
<li>Cordova Google Cloud Messaging Plugin Demo</li>
93+
</ul>
94+
</div>
95+
</body>
96+
</html>

Example/jquery_1.5.2.min.js

+16
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Example/pushAPNS.rb

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
require 'rubygems'
2+
require 'pushmeup'
3+
4+
5+
APNS.host = 'gateway.sandbox.push.apple.com'
6+
APNS.port = 2195
7+
APNS.pem = '</path/to/my/certificate/ck.pem>'
8+
APNS.pass = '<myCertificatePassword>'
9+
10+
device_token = '<device token gleaned from xcode console>'
11+
# APNS.send_notification(device_token, 'Hello iPhone!' )
12+
APNS.send_notification(device_token, :alert => 'PushPlugin works!!', :badge => 1, :sound => 'beep.wav')

Example/pushGCM.rb

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
require 'rubygems'
2+
require 'pushmeup'
3+
GCM.host = 'https://android.googleapis.com/gcm/send'
4+
GCM.format = :json
5+
GCM.key = "AIzaSyB9bWG4OL5-m0eSE5PYaOhsE4lvKwpWBeg"
6+
destination = ["APA91bHi2_juaN9NMBn8bh2rzC-VTg47E8DckJzxVyVr8zxOHI-IswZZibeyyNQo6Wj9u7XVHs_eizoILByPODGtYo71O0qjGaqOoloq6fRBc8DyhQCR1KmZY6qOlUJAKqE21pD5VGN9"]
7+
data = {:message => "this is a test", :msgcnt => "1"}
8+
GCM.send_notification( destination, data)

MIT-LICENSE

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Copyright 2012 Bob Easterday, Adobe Systems
2+
3+
Permission is hereby granted, free of charge, to any person obtaining
4+
a copy of this software and associated documentation files (the
5+
"Software"), to deal in the Software without restriction, including
6+
without limitation the rights to use, copy, modify, merge, publish,
7+
distribute, sublicense, and/or sell copies of the Software, and to
8+
permit persons to whom the Software is furnished to do so, subject to
9+
the following conditions:
10+
11+
The above copyright notice and this permission notice shall be
12+
included in all copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

0 commit comments

Comments
 (0)