Open bmwertman opened 7 years ago
@bmwertman I'm also facing the same issue. Were you able to find a workaround?
I had no success with it. I'm now in progress of switching to the Phonegap plugin. https://github.com/phonegap/phonegap-plugin-push
I find the API to be a little more robust and the documentation is more detailed. It has been going more smoothly but is still not quite working completely.
I've got the same problem. Push is received by the Android device, but always in background mode. If I tap onto it the App opens but onNotification() is never triggered. If the App is in Foreground, the callback also is never triggered....
@colorao I was experiencing the same issue before. Found out it was because I am using firebase console to test to send the notification. Firebase console doesnt have "click_action":"FCM_PLUGIN_ACTIVITY" property in the payload. Try using https://cordova-plugin-fcm.appspot.com/ instead
I tried with "click_action":"FCM_PLUGIN_ACTIVITY" property, with and without custom data values, with and without application open. My app just opens normally like running from a simple click. I need to detect the click is received from the notification ,but the function onNotification() is not solving the problem, i tried to include this function on any angluar run() and on controllers too but still nothing :(
I found the problem, its simple really, the FCMPlugin is not loaded even if you include it at run or controller, the best way to correctly run the onNotification or getToken or other functions of fcm plugin is to put an interval only at your init contoller or at run() since i'm using ionic, in my example this interval gets clear making the script run only once on each app run:
if(typeof check_fcm_loaded==='undefined'){
var check_fcm_loaded = setInterval(function(){
if(typeof FCMPlugin!=='undefined'){
var regToken = function(registeredToken){
setTimeout(function(){
// alert(registeredToken);
// console.log(registeredToken);
// new token received
if( localStorage.token && localStorage.token != registeredToken // its a new token
&& localStorage.instance ){
var newToken = {token: registeredToken, instance: localStorage.instance};
$http.post($rootScope.srv + '?newToken=1', newToken, $rootScope.httpConfig).then(function successCallback(response) {
// response.data
}, function errorCallback(response) {
// alert('no internet connecton probably!')
});
}
localStorage.token = registeredToken;
}, 4000);
};
var errRegToken = function(err){
console.log('error retrieving token: ' + err);
}
FCMPlugin.getToken(regToken, errRegToken);
FCMPlugin.onTokenRefresh(regToken, errRegToken);
FCMPlugin.onNotification(function(data){
alert('notification clicked YAYYY');
if(data.wasTapped){
alert('notification clicked YAYYY #2');
//Notification was received on device tray and tapped by the user.
// alert( JSON.stringify(data) );
}else{
//Notification was received in foreground. Maybe the user needs to be notified.
// alert( JSON.stringify(data) );
}
// open the search filtered by topic
if(localStorage.interes){
// localStorage.interes
localStorage.interesNotification=true;
$state.go('app.search');
}
}, function(msg){ // function registered successfuly
// alert(msg); // typically msg='OK'
}, function(err){
console.log(err);
});
clearInterval(check_fcm_loaded);
}
}, 2000);
}
This how the FCMPlugin was declared back in the day when we had declarations.d.ts. However, now we don't have a declarations.d.ts file in ionic. Therefore, how can we declare it? I didn't find any solutions yet.
I think I found out that you can declare it on the top of the ts file you need the declaration just below the imports.
The issue I'm seeing sounds kind of similar to what is described with issue #123. But I wasn't certain so I thought I would add my own details to be sure.
This was all working when I set it up about a month ago. I still receive push notifications when the app is closed or in the background.
But if the app is in the foreground I get no notification. Which is actually fine because I was handling that with
FCMPlugin.onNotification
callback when everything was working.And
FCMPlugin.onNotification
callback, success or error in my$ionPlatform.ready()
never run no matter the state of the app.Subscribe factory - Used in Rooms factory
Rooms factory - registers chatters for push notifications
app.js .run() - Supposed to listen for incoming notifications and handle them according to the state of the app but it isn't.
node-gcm push router - Hosted on Heroku all chats hit routers url
The send message method