-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
351 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Adobe PhoneGap Build iOS/Android Push Notifications with Realtime | ||
This project shows how to build an Android app able to receive APNS and GCM push notifications built using the [Adobe PhoneGap Build](https://build.phonegap.com/) and the Realtime [CordovaPush](https://build.phonegap.com/plugins/3684) plugin. | ||
|
||
## Push notifications setup guide | ||
|
||
- Create a Google project, more info [here](http://messaging-public.realtime.co/documentation/starting-guide/mobilePushGCM.html). | ||
|
||
- Enter your Realtime Application Key and Google Project Number at the `OrtcPushPlugin.connect` call: | ||
|
||
- Set the `push-notification` event listener: | ||
|
||
document.addEventListener("push-notification", function(notification) { | ||
var payload = document.getElementById('payload'); | ||
payload.innerHTML = JSON.stringify( notification.payload ); | ||
payload.value = JSON.stringify( notification.payload ); | ||
}, false); | ||
|
||
- Add the `CordovaPush` plugin to your `config.xml` file: | ||
|
||
<gap:plugin name="co.realtime.plugins.cordovapush" version="0.1.4" /> | ||
## Testing the app | ||
Start the app, enter a channel name and subscribe to it. | ||
|
||
Now open the Realtime Web Console at [http://console.realtime.co](http://console.realtime.co), enter your Realtime Application Key, connect and send a message to the channel you have subscribed in the app. | ||
|
||
If the app is in background or closed you should see a new message added to your notification manager. Tapping it will open the app and show the push payload in the UI. | ||
|
||
If the app is in foreground you should see the push payload immediately in the UI. | ||
|
||
## Documentation | ||
The CordovaPush Plugin Documentation can be found [here](https://github.com/realtime-framework/CordovaPush). | ||
|
||
The complete Realtime® Messaging reference documentation is available [here](http://framework.realtime.co/messaging/#documentation) | ||
|
||
## Security note | ||
|
||
For simplicity these samples assume you're using a Realtime® Framework developers' application key with the authentication service disabled (every connection will have permission to publish and subscribe to any channel). For security guidelines please refer to the [Security Guide](http://messaging-public.realtime.co/documentation/starting-guide/security.html). | ||
|
||
**Don't forget to replace `YOUR_APPLICATION_KEY` with your own application key. If you don't already own a free Realtime Messaging application key, [get one now](https://accounts.realtime.co/signup/).** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?xml version='1.0' encoding='utf-8'?> | ||
<widget id="co.realtime.CordovaPush" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:gap="http://phonegap.com/ns/1.0" xmlns:cdv="http://cordova.apache.org/ns/1.0"> | ||
<name>Adobe PhoneGap Build Push Notifications</name> | ||
<description> | ||
This project shows how to build an iOS/Android app able to receive APNA/GCM push notifications built using Adobe PhoneGap Build | ||
</description> | ||
<author email="[email protected]" href="http://framework.realtime.co/messaging/"> | ||
Realtime | ||
</author> | ||
<content src="index.html" /> | ||
<plugin name="cordova-plugin-whitelist" version="1" /> | ||
<access origin="*" /> | ||
<allow-intent href="http://*/*" /> | ||
<allow-intent href="https://*/*" /> | ||
<allow-intent href="tel:*" /> | ||
<allow-intent href="sms:*" /> | ||
<allow-intent href="mailto:*" /> | ||
<allow-intent href="geo:*" /> | ||
<platform name="android"> | ||
<allow-intent href="market:*" /> | ||
</platform> | ||
<platform name="android"> | ||
<allow-intent href="itms:*" /> | ||
<allow-intent href="itms-apps:*" /> | ||
</platform> | ||
<gap:plugin name="co.realtime.plugins.cordovapush" version="0.1.4" /> | ||
<gap:platform name="ios" /> | ||
<gap:platform name="android" /> | ||
</widget> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
* { | ||
-webkit-tap-highlight-color: rgba(0,0,0,0); /* make transparent link selection, adjust last value opacity 0 to 1.0 */ | ||
} | ||
|
||
body { | ||
-webkit-touch-callout: none; /* prevent callout to copy image, etc when tap to hold */ | ||
-webkit-text-size-adjust: none; /* prevent webkit from resizing text to fit */ | ||
-webkit-user-select: none; /* prevent copy paste, to allow, change 'none' to 'text' */ | ||
background-color:#E4E4E4; | ||
background-image:linear-gradient(top, #A7A7A7 0%, #E4E4E4 51%); | ||
background-image:-webkit-linear-gradient(top, #A7A7A7 0%, #E4E4E4 51%); | ||
background-image:-ms-linear-gradient(top, #A7A7A7 0%, #E4E4E4 51%); | ||
background-image:-webkit-gradient( | ||
linear, | ||
left top, | ||
left bottom, | ||
color-stop(0, #A7A7A7), | ||
color-stop(0.51, #E4E4E4) | ||
); | ||
background-attachment:fixed; | ||
font-family:'HelveticaNeue-Light', 'HelveticaNeue', Helvetica, Arial, sans-serif; | ||
font-size:12px; | ||
height:100%; | ||
margin:0px; | ||
padding:0px; | ||
text-transform:uppercase; | ||
width:100%; | ||
} | ||
|
||
/* Portrait layout (default) */ | ||
.app { | ||
background:url(../img/logo.png) no-repeat center top; /* 170px x 200px */ | ||
position:absolute; /* position in the center of the screen */ | ||
left:50%; | ||
top:50%; | ||
height:50px; /* text area height */ | ||
width:225px; /* text area width */ | ||
text-align:center; | ||
padding:180px 0px 0px 0px; /* image height is 200px (bottom 20px are overlapped with text) */ | ||
margin:-115px 0px 0px -112px; /* offset vertical: half of image height and text area height */ | ||
/* offset horizontal: half of text area width */ | ||
} | ||
|
||
/* Landscape layout (with min-width) */ | ||
@media screen and (min-aspect-ratio: 1/1) and (min-width:400px) { | ||
.app { | ||
background-position:left center; | ||
padding:75px 0px 75px 170px; /* padding-top + padding-bottom + text area = image height */ | ||
margin:-90px 0px 0px -198px; /* offset vertical: half of image height */ | ||
/* offset horizontal: half of image width and text area width */ | ||
} | ||
} | ||
|
||
h1 { | ||
font-size:24px; | ||
font-weight:normal; | ||
margin:0px; | ||
overflow:visible; | ||
padding:0px; | ||
text-align:center; | ||
} | ||
|
||
.event { | ||
border-radius:4px; | ||
-webkit-border-radius:4px; | ||
color:#FFFFFF; | ||
font-size:12px; | ||
margin:0px 30px; | ||
padding:2px 0px; | ||
} | ||
|
||
.event.listening { | ||
background-color:#333333; | ||
display:block; | ||
} | ||
|
||
.event.received { | ||
background-color:#4B946A; | ||
display:none; | ||
} | ||
|
||
@keyframes fade { | ||
from { opacity: 1.0; } | ||
50% { opacity: 0.4; } | ||
to { opacity: 1.0; } | ||
} | ||
|
||
@-webkit-keyframes fade { | ||
from { opacity: 1.0; } | ||
50% { opacity: 0.4; } | ||
to { opacity: 1.0; } | ||
} | ||
|
||
.blink { | ||
animation:fade 3000ms infinite; | ||
-webkit-animation:fade 3000ms infinite; | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
<!DOCTYPE html> | ||
<!-- | ||
Licensed to the Apache Software Foundation (ASF) under one | ||
or more contributor license agreements. See the NOTICE file | ||
distributed with this work for additional information | ||
regarding copyright ownership. The ASF licenses this file | ||
to you under the Apache License, Version 2.0 (the | ||
"License"); you may not use this file except in compliance | ||
with the License. You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, | ||
software distributed under the License is distributed on an | ||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
KIND, either express or implied. See the License for the | ||
specific language governing permissions and limitations | ||
under the License. | ||
--> | ||
<html> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<meta name="format-detection" content="telephone=no" /> | ||
<!-- WARNING: for iOS 7, remove the width=device-width and height=device-height attributes. See https://issues.apache.org/jira/browse/CB-4323 --> | ||
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" /> | ||
<link rel="stylesheet" type="text/css" href="css/index.css" /> | ||
<meta name="msapplication-tap-highlight" content="no" /> | ||
<title>Hello World</title> | ||
</head> | ||
<body> | ||
<img src="img/realtime.png" alt="realtime logo" id="logo"/> | ||
<h1>PhoneGap Build Push Notifications</h1> | ||
<div class="app"> | ||
<h2>Channel:</h2> | ||
<div id="subcribed" class="event listening">Not subscribed</div> | ||
<br/> | ||
<input type="text" id="channel" /> | ||
<br/> | ||
<input type="button" value="Subscribe push" onclick="subscribe()"/> | ||
<br/> | ||
<h2>Push Payload:</h2> | ||
<label value="Payload result" id="payload" class="event listening">Payload result</label> | ||
<br/> | ||
<input type="button" value="Clear push notifications" onclick="cancelNotifications()"/> | ||
<br/> | ||
<h2>Send Message:</h2> | ||
<input type="text" id="channelMsg" /> | ||
<br/> | ||
<input type="button" value="Send Message" onclick="sendMessage()"/> | ||
</div> | ||
<script src="phonegap.js"></script> | ||
<script type="text/javascript" src="js/index.js"></script> | ||
<script type="text/javascript" src="js/plugins/OrtcPlugin.js"></script> | ||
<script type="text/javascript"> | ||
|
||
app.initialize(); | ||
|
||
function subscribe() | ||
{ | ||
if(window.plugins && window.plugins.OrtcPushPlugin){ | ||
var OrtcPushPlugin = window.plugins.OrtcPushPlugin; | ||
OrtcPushPlugin.log("Connecting"); | ||
|
||
OrtcPushPlugin.connect({'appkey':'<YOUR_APPK_KEY>', | ||
'token':'appToken', | ||
'metadata':'androidMetadata', | ||
'projectId':'<YOUR_GOOGLE_PROJECT_NUMBER>', | ||
'url':'https://ortc-developers.realtime.co/server/ssl/2.1/' | ||
}, function (){ | ||
OrtcPushPlugin.log("Connected: "); | ||
var channel = document.getElementById('channel'); | ||
OrtcPushPlugin.log("Trying to subscribe: " + channel.value); | ||
OrtcPushPlugin.subscribe({'channel':channel.value}, function (){ | ||
var subcribed = document.getElementById('subcribed'); | ||
subcribed.innerHTML = "subscribed: " + channel.value; | ||
OrtcPushPlugin.log("subscribed: " + channel.value); | ||
window.plugins.OrtcPushPlugin.disconnect(); | ||
}); | ||
}); | ||
} | ||
}; | ||
|
||
function cancelNotifications() | ||
{ | ||
if(window.plugins && window.plugins.OrtcPushPlugin){ | ||
var OrtcPushPlugin = window.plugins.OrtcPushPlugin; | ||
OrtcPushPlugin.log("Clearing notifications"); | ||
OrtcPushPlugin.cancelAllLocalNotifications(function(){ | ||
alert('Notifications cleared') | ||
}); | ||
} | ||
}; | ||
|
||
function sendMessage() | ||
{ | ||
if(window.plugins && window.plugins.OrtcPushPlugin){ | ||
var OrtcPushPlugin = window.plugins.OrtcPushPlugin; | ||
var channelSend = document.getElementById('channel'); | ||
var messageSend = document.getElementById('channelMsg'); | ||
OrtcPushPlugin.send({'channel':channelSend.value,'message':messageSend.value},function(){alert('Message sent!')},function(){alert('Error sending message!')}); | ||
|
||
} | ||
}; | ||
|
||
document.addEventListener("push-notification", function(notification){ | ||
window.plugins.OrtcPushPlugin.log("Push-Received channel: " + notification.channel + " extra: " + notification.payload); | ||
var payload = document.getElementById('payload'); | ||
payload.innerHTML = JSON.stringify( notification.payload ); | ||
payload.value = JSON.stringify( notification.payload ); | ||
}, false); | ||
|
||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
var app = { | ||
// Application Constructor | ||
initialize: function() { | ||
this.bindEvents(); | ||
}, | ||
// Bind Event Listeners | ||
// | ||
// Bind any events that are required on startup. Common events are: | ||
// 'load', 'deviceready', 'offline', and 'online'. | ||
bindEvents: function() { | ||
document.addEventListener('deviceready', this.onDeviceReady, false); | ||
}, | ||
// deviceready Event Handler | ||
// | ||
// The scope of 'this' is the event. In order to call the 'receivedEvent' | ||
// function, we must explicitly call 'app.receivedEvent(...);' | ||
onDeviceReady: function() { | ||
app.receivedEvent('deviceready'); | ||
}, | ||
// Update DOM on a Received Event | ||
receivedEvent: function(id) { | ||
var parentElement = document.getElementById(id); | ||
var listeningElement = parentElement.querySelector('.listening'); | ||
var receivedElement = parentElement.querySelector('.received'); | ||
|
||
listeningElement.setAttribute('style', 'display:none;'); | ||
receivedElement.setAttribute('style', 'display:block;'); | ||
|
||
console.log('Received Event: ' + id); | ||
} | ||
}; | ||
|
||
app.initialize(); |