Permalink
Fetching contributors…
Cannot retrieve contributors at this time
81 lines (67 sloc) 2.19 KB
<!DOCTYPE HTML>
<html>
<head>
<title>Demo</title>
</head>
<body>
<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
<script type="text/javascript" charset="utf-8" src="jquery_1.5.2.min.js"></script>
<script type="text/javascript">
function onDeviceReady() {
var pushConfig = {
pushServerURL: "<pushServerURL e.g http(s)//host:port/context >",
alias: "<alias e.g. a username or an email address optional>",
android: {
senderID: "<senderID e.g Google Project ID only for android>",
variantID: "<variantID e.g. 1234456-234320>",
variantSecret: "<variantSecret e.g. 1234456-234320>"
},
ios: {
variantID: "<variantID e.g. 1234456-234320>",
variantSecret: "<variantSecret e.g. 1234456-234320>"
}
};
var statusList = $("#app-status-ul");
statusList.append('<li>deviceready event received</li>');
try {
statusList.append('<li>registering </li>');
push.register(onNotification, successHandler, errorHandler, pushConfig);
} catch (err) {
txt = "There was an error on this page.\n\n";
txt += "Error description: " + err.message + "\n\n";
alert(txt);
}
}
function onNotification(e) {
var statusList = $("#app-status-ul");
// on android we could play the sound, if we add the Media plugin
if (e.sound && (typeof Media != 'undefined')) {
var media = new Media("/android_asset/www/" + e.sound + '.wav');
media.play();
}
if (e.coldstart) {
statusList.append('<li>--COLDSTART NOTIFICATION--' + '</li>');
}
statusList.append('<li>MESSAGE -> MSG: ' + e.alert + '</li>');
//only on ios
if (e.badge) {
push.setApplicationIconBadgeNumber(successHandler, e.badge);
}
}
function successHandler() {
$("#app-status-ul").append('<li>success</li>');
}
function errorHandler(error) {
$("#app-status-ul").append('<li>error:' + error + '</li>');
}
document.addEventListener('deviceready', onDeviceReady, true);
</script>
<div id="home">
<div id="app-status-div">
<ul id="app-status-ul">
<li>AeroGear PushPlugin Unified Push Demo</li>
</ul>
</div>
</div>
</body>
</html>