Start a new topic

Push notification from Collection Hook

Hey guys, I've trying everything but I can't get push notifications to work.



I have the following code:



//=====================

var findUser = function( id, callback )

{

userCollection.findOne( { "_id": userCollection.objectID( id ) }, function( error, foundUser ){



if( !error )

{

if( callback ) callback( foundUser );

}

else

{

logger.error( request.method + ": Error finding user: " + error );

if( callback) callback( null );

}

});

};



findUser( report.user._id, function( user ){

if( user )

{

logger.info( "user to push: " + user.name );

modules.push.sendMessage( user, "Test from hook" );

}

});

//=====================



The console log shows the user name as the logger.info say. But no notification is sent =/

When I go to the push test console and broadcast the test message to test my configuration, it works!



Please, what am I doing wrong?



Also, once you help to fix this, is there any secret to configure custom payloads for push?

Thank you so much!

Suddenly it started to work. So I went out to lunch and when I got back, it stopped again without any modification. Seems that the push service is unstable. Is it normal?
Sorry, in my previous message, the forum supressed the device token. Trying again:



{

"_devicetokens": [

"beae93dc6738f29a84a088f0ffc8de4a0977081ce2066342cd6c734a8605e354"

]

}



This is what appears on the console.

Thanks
Hi Michael, thank you for your help. But, it still not working for me.

I've tested if user has the device token as you said and is there.



if( user._push )

{

logger.info( user._push );

push.send( user, aps.alert );

}



The console log says:



{

"_devicetokens": [

""

]

}



any other suggestions?
Check that the _push value of the user contains a token for either _devicetokens or for GCM (for iOS and Android, respectively). If the token is not there, it may occur in a broadcast but not a sendPush.



For custom payloads, you can use the sendPayload method found at http://devcenter.kinvey.com/reference/business-logic/reference.html#Payloads
Login or Signup to post a comment