Search code examples
ionic-frameworkcordova-plugin-fcm

Cordova FCM plugin handle background notification data


I'm using the following code to receive data on my ionic app using firebase, i'm getting data.wastapped = true when the app is in background now i need to pass the data to my main controller,please help me to achieve this

 FCMPlugin.onNotification(
                        function(data){
                            if(data.wasTapped){
    alert(JSON.stringify(data);
    // need to pass this data to my app controller

                                tapped by the user.
                                alert( JSON.stringify(data) );
                            }else{

                                alert( JSON.stringify(data) );
                            }
                        },
                        function(msg){
                            alert('onNotification callback successfully registered: ' + msg);
                        },
                        function(err){
                            alert('Error registering onNotification callback: ' + err);
                        }

Solution

  • @Ram, Try using this below function

    var scope = angular.element(document.getElementById('mainbody')).scope();   
    scope.$apply(function(){
               //show popup regarding alert         
                scope.showdatas(data);
            });