Skip to content

Commit 5882dd9

Browse files
#2 Add 'isRegistered' function
- WP8 support - Cleanup of example app
1 parent 69a4b0d commit 5882dd9

File tree

7 files changed

+52
-125
lines changed

7 files changed

+52
-125
lines changed

Example/server/pushGCM.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
require 'pushmeup'
33
GCM.host = 'https://android.googleapis.com/gcm/send'
44
GCM.format = :json
5-
GCM.key = "API_KEY_GOES_HERE"
6-
destination = ["REGISTRATION_ID_GOES_HERE"]
7-
data = {:message => "PhoneGap Build rocks!", :msgcnt => "1", :soundname => "beep.wav"}
5+
GCM.key = "AIzaSyBUhVPJ2-i_ae6HDihsjCzHMHWdeCrHS6c"
6+
destination = ["APA91bFOtOXXF6nbzdPDbESlDqrnH5nyr3gONb5BhNXjNFghVY_3eYxd0eKpzXlkbAFZ5y-bOZ9xfq2dSwckXhg0jaAlDuuCpHsHExyHGXysPoXhkQVaRXDtkUJDq0md7pixCSfaTKBJTEJ1Ewf751vCQz8ghDg_OwBwMMoVwMZfvXopUmfK2th9sXuWlR4HNpG6-zdKPVMj"]
7+
data = {:message => "Telerik AppBuilder ftw!", :msgcnt => "1"}
88

99
GCM.send_notification( destination, data)

Example/www/PushNotification.js

Lines changed: 0 additions & 65 deletions
This file was deleted.

Example/www/index.html

Lines changed: 33 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
</head>
66
<body>
77

8-
/*
8+
<!--
99
NOTE:
1010
This demo uses these plugins:
1111
Cordova Device Plugin: http://plugins.cordova.io/#/package/org.apache.cordova.device
@@ -14,22 +14,21 @@
1414
To add them via the CLI:
1515
$ cordova plugin add org.apache.cordova.device
1616
$ cordova plugin add org.apache.cordova.media
17-
*/
18-
<!--<script type="text/javascript" charset="utf-8" src="cordova-2.2.0.js"></script>-->
19-
<script type="text/javascript" charset="utf-8" src="phonegap.js"></script>
20-
<script type="text/javascript" charset="utf-8" src="jquery_1.5.2.min.js"></script>
21-
<script type="text/javascript" src="PushNotification.js"></script>
22-
17+
-->
18+
19+
<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
20+
<script type="text/javascript" charset="utf-8" src="https://code.jquery.com/jquery-1.11.1.min.js"></script>
21+
2322
<script type="text/javascript">
2423
var pushNotification;
25-
24+
2625
function onDeviceReady() {
2726
$("#app-status-ul").append('<li>deviceready event received</li>');
28-
27+
2928
document.addEventListener("backbutton", function(e)
3029
{
3130
$("#app-status-ul").append('<li>backbutton event received</li>');
32-
31+
3332
if( $("#home").length > 0)
3433
{
3534
// call this to get a new token each time. don't call it to reuse existing token.
@@ -42,9 +41,9 @@
4241
navigator.app.backHistory();
4342
}
4443
}, false);
45-
46-
try
47-
{
44+
45+
try
46+
{
4847
pushNotification = window.plugins.pushNotification;
4948
$("#app-status-ul").append('<li>registering ' + device.platform + '</li>');
5049
if (device.platform == 'android' || device.platform == 'Android' ||
@@ -54,37 +53,37 @@
5453
pushNotification.register(tokenHandler, errorHandler, {"badge":"true","sound":"true","alert":"true","ecb":"onNotificationAPN"}); // required!
5554
}
5655
}
57-
catch(err)
58-
{
59-
txt="There was an error on this page.\n\n";
60-
txt+="Error description: " + err.message + "\n\n";
61-
alert(txt);
62-
}
56+
catch(err)
57+
{
58+
txt="There was an error on this page.\n\n";
59+
txt+="Error description: " + err.message + "\n\n";
60+
alert(txt);
61+
}
6362
}
64-
63+
6564
// handle APNS notifications for iOS
6665
function onNotificationAPN(e) {
6766
if (e.alert) {
6867
$("#app-status-ul").append('<li>push-notification: ' + e.alert + '</li>');
6968
// showing an alert also requires the org.apache.cordova.dialogs plugin
7069
navigator.notification.alert(e.alert);
7170
}
72-
71+
7372
if (e.sound) {
7473
// playing a sound also requires the org.apache.cordova.media plugin
7574
var snd = new Media(e.sound);
7675
snd.play();
7776
}
78-
77+
7978
if (e.badge) {
8079
pushNotification.setApplicationIconBadgeNumber(successHandler, e.badge);
8180
}
8281
}
83-
82+
8483
// handle GCM notifications for Android
8584
function onNotification(e) {
8685
$("#app-status-ul").append('<li>EVENT -> RECEIVED:' + e.event + '</li>');
87-
86+
8887
switch( e.event )
8988
{
9089
case 'registered':
@@ -96,15 +95,15 @@
9695
console.log("regID = " + e.regid);
9796
}
9897
break;
99-
98+
10099
case 'message':
101100
// if this flag is set, this notification happened while we were in the foreground.
102101
// you might want to play a sound to get the user's attention, throw up a dialog, etc.
103102
if (e.foreground)
104103
{
105104
$("#app-status-ul").append('<li>--INLINE NOTIFICATION--' + '</li>');
106-
107-
// on Android soundname is outside the payload.
105+
106+
// on Android soundname is outside the payload.
108107
// On Amazon FireOS all custom attributes are contained within payload
109108
var soundfile = e.soundname || e.payload.sound;
110109
// if the notification contains a soundname, play it.
@@ -120,38 +119,38 @@
120119
else
121120
$("#app-status-ul").append('<li>--BACKGROUND NOTIFICATION--' + '</li>');
122121
}
123-
122+
124123
$("#app-status-ul").append('<li>MESSAGE -> MSG: ' + e.payload.message + '</li>');
125124
//android only
126125
$("#app-status-ul").append('<li>MESSAGE -> MSGCNT: ' + e.payload.msgcnt + '</li>');
127126
//amazon-fireos only
128127
$("#app-status-ul").append('<li>MESSAGE -> TIMESTAMP: ' + e.payload.timeStamp + '</li>');
129128
break;
130-
129+
131130
case 'error':
132131
$("#app-status-ul").append('<li>ERROR -> MSG:' + e.msg + '</li>');
133132
break;
134-
133+
135134
default:
136135
$("#app-status-ul").append('<li>EVENT -> Unknown, an event was received and we do not know what it is</li>');
137136
break;
138137
}
139138
}
140-
139+
141140
function tokenHandler (result) {
142141
$("#app-status-ul").append('<li>token: '+ result +'</li>');
143142
// Your iOS push server needs to know the token before it can push to this device
144143
// here is where you might want to send it the token for later use.
145144
}
146-
145+
147146
function successHandler (result) {
148147
$("#app-status-ul").append('<li>success:'+ result +'</li>');
149148
}
150-
149+
151150
function errorHandler (error) {
152151
$("#app-status-ul").append('<li>error:'+ error +'</li>');
153152
}
154-
153+
155154
document.addEventListener('deviceready', onDeviceReady, true);
156155

157156
</script>

Example/www/jquery_1.5.2.min.js

Lines changed: 0 additions & 16 deletions
This file was deleted.

src/android/com/plugin/gcm/PushPlugin.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@
55
import android.os.Bundle;
66
import android.util.Log;
77
import com.google.android.gcm.GCMRegistrar;
8-
import org.apache.cordova.CallbackContext;
9-
import org.apache.cordova.CordovaInterface;
10-
import org.apache.cordova.CordovaPlugin;
11-
import org.apache.cordova.CordovaWebView;
8+
import org.apache.cordova.*;
129
import org.json.JSONArray;
1310
import org.json.JSONException;
1411
import org.json.JSONObject;

src/wp8/PushPlugin.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.Diagnostics;
44
using System.IO;
@@ -77,6 +77,18 @@ public void unregister(string options)
7777
}
7878
}
7979

80+
public void isRegistered(string options)
81+
{
82+
Options isRegisteredOptions;
83+
if (!TryDeserializeOptions(options, out isRegisteredOptions))
84+
{
85+
this.DispatchCommandResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION));
86+
return;
87+
}
88+
var pushChannel = HttpNotificationChannel.Find(isRegisteredOptions.ChannelName);
89+
this.DispatchCommandResult(new PluginResult(PluginResult.Status.OK, pushChannel != null));
90+
}
91+
8092
public void showToastNotification(string options)
8193
{
8294
ShellToast toast;

www/PushNotification.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ PushNotification.prototype.unregister = function(successCallback, errorCallback,
3737
};
3838

3939
// Check to see if we've already registered
40-
PushNotification.prototype.isRegistered = function(successCallback, errorCallback) {
40+
PushNotification.prototype.isRegistered = function(successCallback, errorCallback, options) {
4141
if (errorCallback == null) { errorCallback = function() {}}
4242

4343
if (typeof errorCallback != "function") {
@@ -50,7 +50,7 @@ PushNotification.prototype.isRegistered = function(successCallback, errorCallbac
5050
return
5151
}
5252

53-
cordova.exec(successCallback, errorCallback, "PushPlugin", "isRegistered", []);
53+
cordova.exec(successCallback, errorCallback, "PushPlugin", "isRegistered", [options]);
5454
};
5555

5656
// Call this if you want to show toast notification on WP8

0 commit comments

Comments
 (0)