Push Notification

14 posts, 0 answers
  1. karan
    karan avatar
    6 posts
    Member since:
    Jul 2014

    Posted 11 Aug 2014 Link to this post

    I work with Push  Notification in telerik with Backend Services (Push) , it works fine. But i want to implement push notification in telerik without BackEnd Services and send notification from my php script.Does telerik support  Push notification without its backend Services.
  2. Anton Dobrev
    Admin
    Anton Dobrev avatar
    539 posts

    Posted 13 Aug 2014 Link to this post

    Hi Karan,

    The Push notifications feature in Backend Services enables you to send push notifications and manage devices without the need to build your own intermediary server that does that and a database that stores the information about the devices.

    You can send push notifications to the devices registered in your BS project by communicating with the Backend Services API from your PHP script. You can see the API reference and samples how to send, target and retrieve the notifications in the following documentation article: Sending Push Notifications.

    Please, let me know if you have further questions.

    Regards,
    Anton Dobrev
    Telerik
     
    Everlive is now Telerik Backend Services, and is part of the Telerik Platform.
     
  3. karan
    karan avatar
    6 posts
    Member since:
    Jul 2014

    Posted 18 Aug 2014 in reply to Anton Dobrev Link to this post

    I am facing problem with Push Notification , I successfully register my Device in GCM and get back my token ID. Now , when i send Notification from server , notification send successfully from server but i didn't receive notification on mobile and  App get crashed.
  4. Anton Dobrev
    Admin
    Anton Dobrev avatar
    539 posts

    Posted 19 Aug 2014 Link to this post

    Hello Karan,

    We will need more details on the issue you are experiencing.

    Could you please specify how does the app crash? Could it be connected to the logic that handles the event when a notification object is received? Are the token and the parameters of the device sent to the server after you receive the token?

    In order to assist you further we will need to observe the code used to obtain a token from GCM and what is the logic that handles the notification received event (sample code that reproduces the problem would be very helpful).

    I am looking forward to your reply.

    Regards,
    Anton Dobrev
    Telerik
     
    Everlive is now Telerik Backend Services, and is part of the Telerik Platform.
     
  5. karan
    karan avatar
    6 posts
    Member since:
    Jul 2014

    Posted 23 Aug 2014 in reply to Anton Dobrev Link to this post

    I am sending you code which i used in my app , so that you can better understand my problem regarding push notification and app crash when i send notification to app. I am checking notification on Android mobile.

    var onDeviceReady = function() {
           
            document.addEventListener('backbutton', onBackKeyDown, false);
              
             var pushNotification = window.plugins.pushNotification;
    console.log(window.plugins);
               
            if (device.platform === "iOS") {
                pushNotification.register(apnSuccessfulRegistration,
                apnFailedRegistration, {
                    "badge": "true",
                    "sound": "true",
                    "alert": "true",
                    "ecb": "pushCallbacks.onNotificationAPN"
                });
     
            } else {
                //register for GCM
                pushNotification.register( 
                function(id) {
                    console.log("###Successfully sent request for registering with GCM.");
                    //set GCM notification callback
                    addCallback('onNotificationGCM', onNotificationGCM);
                },
     
                function(error) {
                    console.log("###Error " + error.toString());
                }, {
                    "senderID": "****************", // HERE IS MY SENDER ID
                    "ecb": "pushCallbacks.onNotificationGCM"
                });
            }
        };


        
    var addCallback = function addCallback(key, callback) {
            if (window.pushCallbacks === undefined) {
                window.pushCallbacks = {}
            }
            window.pushCallbacks[key] = callback;
        };
     
     
       
     var apnSuccessfulRegistration = function(token) {
            console.log(token);
            //sendTokenToServer(token.toString(16));
            addCallback('onNotificationAPN', onNotificationAPN);
        }
     
        
    var apnFailedRegistration = function(error) {
            console.log("Error: " + error.toString());
      
      }
     
        //the function is a callback when a notification from APN is received
       
     var onNotificationAPN = function(e) {
            console.log(e);
            //getPromotionFromServer();
        };
     
        //the function is a callback for all GCM events
       
     var onNotificationGCM = function onNotificationGCM(e) {
            switch (e.event) {
                case 'registered':
                    if (e.regid.length > 0) {
                        //your GCM push server needs to know the regID before it can push to this device
                        //you can store the regID for later use here
                        console.log('###token received');
                        //alert("TokenID Received" + e.regid); // HERE I GET MY TOKEN ID
                        localStorage.setItem("deviceTokenID",e.regid);
                        //sendTokenToServer(e.regid);
                    }
                    break;
                case 'message':
                    alert('hello2'); // THIS ALERT NOT SHOWING
                break;
                case 'error':
                    alert('GCM error = ' + e.msg);
                    break;
                default:
                    alert('An unknown GCM event has occurred.');
                    break;
            }
        };  
  6. Anton Dobrev
    Admin
    Anton Dobrev avatar
    539 posts

    Posted 26 Aug 2014 Link to this post

    Hello Karan,

    A wild guess would be that on your side some code logic is executing before the "deviceready" event is emitted and blocks the app. Unfortunately, the provided code sample is not sufficient for us to reproduce the way your app crashes. This code is correct as it sticks to the official sample of the Cordova PushPlugin.

    We have a very simple project that works as expected using the code above. You can find it attached. Just enter the project number in the app, import it in your favorite AppBuilder client and deploy it to your Android device. Once you obtain the token for the device you can test the sending of push notifications from the Android GCM sender client for WIndows in order to eliminate the server part of the whole process. Just enter your GCM API key for server applications and the token of the device in the text inputs and send a push payload for example: "message" : "hello". The notification should be received and dispatched to the app.

    Let me know if this works for you and if you have further questions.

    Best regards,
    Anton Dobrev
    Telerik
     
    Everlive is now Telerik Backend Services, and is part of the Telerik Platform.
     
  7. karan
    karan avatar
    6 posts
    Member since:
    Jul 2014

    Posted 29 Aug 2014 in reply to Anton Dobrev Link to this post

    I like to thank you for giving me your important time and providing me important help . I didn't know about  Android GCM sender client for WIndows Previously , this was help . Now , my app receives notification properly . Please let me know , does phonegap support attachment with notification. Like if we want to send image in notification as attachment . How we get it , in telerik app
  8. Anton Dobrev
    Admin
    Anton Dobrev avatar
    539 posts

    Posted 01 Sep 2014 Link to this post

    Hello Karan,

    Unfortunately, attachments are not supported in the notification payload. It can consist only from key-value pairs. For reference, you can take a look into the supported structure for push notifications in Backend Services. When a notification is received these values can be parsed by the event handler. For instance, you can pass a URL address with the payload and open it when the notification is received.

    Let me know if you have further questions.

    Regards,
    Anton Dobrev
    Telerik
     
    Everlive is now Telerik Backend Services, and is part of the Telerik Platform.
     
  9. karan
    karan avatar
    6 posts
    Member since:
    Jul 2014

    Posted 10 Sep 2014 in reply to Anton Dobrev Link to this post

    I try to add plugin automatically using import from App Builder , but plugin not able to work. How can i add plugin in app builder . Also please let me know , where can i find java files of telerik push plugin(Provide by telerik). Is it available for user or not.Can we make changes in its file , like i want to open specific app page , when i receive push notification.
  10. Anton Dobrev
    Admin
    Anton Dobrev avatar
    539 posts

    Posted 12 Sep 2014 Link to this post

    Hello,

    I tried and updated without problems the previous sample project with the plugin donwloaded from the Telerik Verified Plugins Marketplace. You can find it attached. Note that you need to disable the integrated Push plugin in order to use the imported one.

    Also, you can browse the plugin's structure from the Data Navigator > Plugins >  in your favorite AppBuilder client. If you need to make changes to the plugin you may take a look into the Cordova's plugin development guide.

    Specifically, for the functionality you would like to achieve you can use the callback function that is called when a notification is received. Note that if the app is not running and is started from a notification tapped by the user, you will need to register the device again for notifications. If this returns successfully the notificationReceived callback will be executed.

    Regards,
    Anton Dobrev
    Telerik
     
    Everlive is now Telerik Backend Services, and is part of the Telerik Platform.
     
  11. Isaac
    Isaac avatar
    3 posts
    Member since:
    Oct 2014

    Posted 02 Nov 2014 in reply to karan Link to this post

    i have downloaded and loaded the karanpush.zip file in my app buillder I went into the index.js file and inserterd the registration ID which in my case is 1016385411338 

    i am trying to send using the Android GCM Sender but no notification is coming it is returning an

     error {"multicast_id":6232176527152091689,"success":0,"failure":1,"canonical_ids":0,"results":[{"error":"InvalidRegistration"}]}

    please may you advise if i am entering the right details and where I get the device token.






  12. Isaac
    Isaac avatar
    3 posts
    Member since:
    Oct 2014

    Posted 03 Nov 2014 in reply to Isaac Link to this post

    got it now sending ok, but no notification on my device??? this is the pop up box that comes after sending using Android GCM NOTIFIER

    Please may you kindly advise how this really works I am developing an app that has to receive a notification first before everything.

    Regards

    Isaac
  13. karan
    karan avatar
    6 posts
    Member since:
    Jul 2014

    Posted 03 Nov 2014 in reply to Isaac Link to this post

    Good , Actually if your app in foreground(active) , you will not able to see notification , if you want pop-up you need to work on js file inside function-:

       var onNotificationGCM = function(e) {
          //alert(JSON.stringify(e));
            
         try{
             
            switch (e.event) {
                case 'registered':
                    if (e.regid.length > 0) {
                        //your GCM push server needs to know the regID before it can push to this device
                        //you can store the regID for later use here
                        console.log('###token received');
                        console.log("TokenID Received" + e.regid);
                        localStorage.setItem("deviceTokenID",e.regid);
                        //sendTokenToServer(e.regid);
                    }
                    break;
                
                case 'message':
                //alert(e);                      
                console.log('----------------------');
                console.log(JSON.stringify(e));           
                //alert(e.title);            
                
                account_IdDB = localStorage.getItem("ACCOUNT_ID");
                
                //alert(account_IdDB);            
                
                var messageSplitVal = e.payload.default.split('#####');
                messageDB = messageSplitVal[0];
                orgIdDB = messageSplitVal[1];
                notiIdDB=messageSplitVal[2];
                typeDB=messageSplitVal[3];
                titleDB=messageSplitVal[4];
                attachedDB=messageSplitVal[5];
                commentAllowDB=messageSplitVal[6];
                notificationMsg=messageSplitVal[7];

                send_DateDB= getPresentDateTime();
                
                if(attachedDB=== 0 || attachedDB=== "0"){
                    attachedDB='';
                }

                if ( e.foreground )
                {
                    if(typeDB!=='Reply'){
                        var db = app.getDb();
                        db.transaction(insertOrgNotiData, app.errorCB, app.successCB);
                    }
                    
                }else{
                    if(typeDB!=='Reply'){
                        var db = app.getDb();
                        db.transaction(insertOrgNotiDataBagINC, app.errorCB, goToAppPage);    
                    }else{
                        typeDB="Reply";
                        var temp;
                        temp=messageDB;
                        messageDB=notificationMsg;
                        notificationMsg=temp;
                        goToAppPage();                    
                    }    
                }
                
               /* if ( e.foreground )
                 {
                    //var soundfile = e.soundname || e.payload.sound;
                    //var my_media = new Media("/android_asset/www/"+ soundfile);
                    //my_media.play();
                    //alert('foreGround');
                        var db = app.getDb();
                        db.transaction(insertOrgNotiData, app.errorCB, app.successCB);    
                }
                    else
                {  // otherwise we were launched because the user touched a notification in the notification tray.
                    if ( e.coldstart )
                    {
                        //alert('coldstart');
                        var db = app.getDb();
                        db.transaction(insertOrgNotiData, app.errorCB, goToAppPage);
                    }
                    else
                    {
                         var db = app.getDb();
                        db.transaction(insertOrgNotiData, app.errorCB, goToAppPage);
                    }
               }*/
                
                
                //return message;
                //alert('message = '+e.message+' msgcnt = '+e.msgcnt);            
                    //getPromotionFromServer();
                    break;
                case 'error':
                    //alert('GCM error = ' + e.msg);
                    break;
                default:
                    //alert('An unknown GCM event has occurred.');
                    break;
            }
          }
          catch(err){
             //alert(err);
          }
          finally {    
            
          }   
        };

    I Guess if you app is not active(close) , you able to receive notification on status bar .
  14. Anton Dobrev
    Admin
    Anton Dobrev avatar
    539 posts

    Posted 05 Nov 2014 Link to this post

    Hi,

    In short - when the app is in the foreground and a notification is received the event will be dispatched to a callback handler that is defined in your app. When the app is in the foreground - the notification is placed in the notification tray of the device.

    Also, you can take a look into the push notifications feature of Telerik Backend Services which will allow you to target, schedule and send cross-platform notifications. You can start from configuring a backend project in your Telerik Platform account and follow the guidelines from the JS SDK.

    Let me know if you have questions.

    Regards,
    Anton Dobrev
    Telerik
     
    Everlive is now Telerik Backend Services, and is part of the Telerik Platform.
     
Back to Top