This is a migrated thread and some comments may be shown as answers.

Push Notification not working

1 Answer 235 Views
General Discussion
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Abhishek
Top achievements
Rank 1
Abhishek asked on 07 Aug 2013, 01:05 PM
Hi 

I am trying to use the Everlive Push Notification without the MVVM template that it comes with. The approach i have taken is to remove the reference of main.js from index.html and include a different js file to host my code. I don't think MVVM should be essential for using Push Notifications.

The code that i currently have is as follows:

"use strict";
document.addEventListener("deviceready", onDeviceReady, false);

// PhoneGap is ready
function onDeviceReady() {
     var app = new kendo.mobile.Application(document.body);
    
    var el = new Everlive('xxxxxxxx');

    var currentDevice;
    
   var successCallback =  function(arg) {
        alert('Device already registered');
        currentDevice= arg;
    }
    
        //el.push.currentDevice().getRegistration(successCallback, function() {alert("Registering the device.");currentDevice = el.push.currentDevice();});

var pushSettings = {
        iOS:{
            badge: true,
            sound: true,
            alert: true
        },
        android:{
            senderID: '55555555555555
        },
        notificationCallbackIOS: function(e){
            alert('Initialized successfully' +  + JSON.stringify(e));
        },
        notificationCallbackAndroid: onAndroidPushReceived
};

el.push.currentDevice().enableNotifications(pushSettings, function() {alert('Initialized successfully');}, function() {alert('Initialization error');});
}


var onAndroidPushReceived = function(args) {
    alert('Notification Received');
            alert('Android notification received: ' + JSON.stringify(args)); 
        };
    

function registerInEverlive() {
    alert("Starting REgistration");
     var el = new Everlive('xxxxxxxxx');
   // el.push.currentDevice().register({ Group: 15 }, function() {alert('Registered successfully');}, function() {alert('Registeration NOT successfully');});
    
    var currentDevice = el.push.currentDevice();
            
            if (!currentDevice.pushToken) currentDevice.pushToken = "some token";
            el.push.currentDevice()
                .register({ Age: 15 })
                .then(
                    function() {
                        alert('Device registered with Everlive');
                    },
                    function(err) {
                        alert('REGISTER ERROR: ' + JSON.stringify(err));
                    }
                );
 
    }


With the above code i am able to register Android device on Everlive (and i am able to confirm the same from the portal). However, any push notification that i send from the portal is not reaching the device. I have supplied the Everlive key, Google API Project ID in the code above. In the Everlive portal, I am using the Server Key (of GCM). 

Earlier, using the template the notifications were able to reach the device. 

Cheers
Abhishek Kant

1 Answer, 1 is accepted

Sort by
0
Lyubomir Dokov
Telerik team
answered on 12 Aug 2013, 02:22 PM
Hello Abhishek,

MVVM is definitely not required for push notifications. Your code seems fine. I assume that you replaced google project ID and your API key with fake values just for the post.

Can you check the push token for the registered device in the portal? Does it seem like a valid push token? You can try if the token itself is valid by using this app:
http://gcm.codeplex.com/

This will help us narrow down the problem area - is it a problem with the push token(e.g. with the registration) or is it some server issue with sending the notification to GCM.

Regards,
Lyubomir Dokov
Telerik

Do you enjoy Icenium? Vote for it as your favorite new product here (use short code H048S).
Looking for tips & tricks directly from the Icenium team? Check out our blog!
Share feedback and vote for features on our Feedback Portal.
Tags
General Discussion
Asked by
Abhishek
Top achievements
Rank 1
Answers by
Lyubomir Dokov
Telerik team
Share this question
or