Skip to content

Adobe PhoneGap Build app using Realtime and Push Notifications for iOS and Android (APNS/GCM)

License

Notifications You must be signed in to change notification settings

realtime-framework/phonegap-push

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 

Repository files navigation

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 and the Realtime CordovaPush plugin.

Push notifications setup guide

  • Create a Google project, more info here.

  • Add deviceready event listener to the HEAD section of your HTML page

      <script type="text/javascript">
           document.addEventListener("deviceready",
                    function () {
                      if(window.plugins && window.plugins.OrtcPushPlugin){
                              var OrtcPushPlugin = window.plugins.OrtcPushPlugin;
                              OrtcPushPlugin.checkForNotifications();
                       }
                     }, false);
      </script>
    
  • 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.2.0" />
    

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, 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.

The complete Realtime® Messaging reference documentation is available here

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.

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.

About

Adobe PhoneGap Build app using Realtime and Push Notifications for iOS and Android (APNS/GCM)

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •