Skip to content
This repository has been archived by the owner on Sep 4, 2020. It is now read-only.

Push Notification when app is in foreground? #925

Closed
omaismbakop opened this issue May 25, 2016 · 9 comments
Closed

Push Notification when app is in foreground? #925

omaismbakop opened this issue May 25, 2016 · 9 comments
Labels

Comments

@omaismbakop
Copy link

omaismbakop commented May 25, 2016

Expected Behaviour

should receive notification when app in background and foreground

Actual Behaviour

i am receiving notification when app in background but not when its in foreground

Reproduce Scenario (including but not limited to)

Steps to Reproduce

Platform and Version (eg. Android 5.0 or iOS 9.2.1)

Android 4.4

(Android) What device vendor (e.g. Samsung, HTC, Sony...)

Samsung

Cordova CLI version and cordova platform version

cordova --version                                    # e.g. 6.0.0
cordova platform version android                     # e.g. 4.1.1

Plugin version

cordova plugin version | grep phonegap-plugin-push   # e.g. 1.5.3

Sample Push Data Payload

Sample Code that illustrates the problem

Logs taken while reproducing problem

I tested, push notification code is executing each time when app starts, Code of initial function

     var push = PushNotification.init(
    { "android": {"senderID": "XXXXXXXXXXXXXXX"
                 },
      "ios": {"alert": "true", "badge": "true", "sound": "true"
             } 

    });

// checking if app already have regisrationID
if (localStorage.getItem("push") === null) {
            localStorage.setItem("push", 1);


        push.on('registration', function(data) {
        console.log(data.registrationId);
        //app.alert(data.registrationId);

           //Ajax call to send registration id to server database 
            var postData = {senderid: data.registrationId};
                                     $.ajax({
                                      // cache: false,
                                      type: 'POST',
                                      url: "XXXXXXXXXXXXXX.php",
                                      //beforeSend: function() { },
                                      // complete: function(){  },
                                      //dataType: "json",
                                      data: postData,
                                      success: function(data) {
                                         // PROCESS DATA HERE
                                          //app.alert(JSON.stringify(data));

                                      },
                                      error: function(data) {
                                         //PROCESS HERE FOR FAILURE
                                         // return View.Modal.openNotification("Error!"); //console.log(data);
                                         app.alert("Network not found");

                                      }
                                  });
        });
}

        push.on('notification', function(data) {
        console.log(data.message);
        alert(data.title+" Message: " +data.message);
        data.title,
        data.sound,
        data.image,
        data.message
            // data.additionalData
        });

        push.on('error', function(e) {
        console.log(e.message);
        });
@ngt14
Copy link

ngt14 commented May 25, 2016

to take your data notification in foreground and see your alert ,you can call the method finish() on your function push.on('notification', function(data). Like that :

push.on('notification', function(data) {
push.finish( function() {
console.log(data.message);
alert(data.title+" Message: " +data.message);
data.title,
data.sound,
data.image,
data.message
// data.additionalData
}
});

@omaismbakop
Copy link
Author

omaismbakop commented May 25, 2016

i can see alert when its in foreground, but only alert dialog. no sound, no vibration, no alert

@macdonst
Copy link
Member

@omaismbakop what you are describing is the way the plugin should work. When the app is in the foreground it is up to you to display a dialog, play a sound or vibrate the device.

@omaismbakop
Copy link
Author

omaismbakop commented May 25, 2016

i make it worked by setting forceShow true like this

      var push = PushNotification.init(
         { "android": {"senderID": "533867441597", "forceShow": "true"
                 },
      "ios": {"alert": "true", "badge": "true", "sound": "true"
             } 

    });

@leizard
Copy link

leizard commented May 30, 2016

Hi @omaismbakop , how about ios ?

@chirag0110
Copy link

Yes, "forceShow": "true" is work for android. What about IOS?

How can i get notification in forground IOS app.

@Dineshrajaa
Copy link

is there any option for force showing notification in iOS app?

@lovelyelfpop
Copy link

I found EBForeNotification, it can show the Banners and Sounds as the same as the system notifications on foreground in ios.
Can someone integrate EBForeNotification into this plugin?

@lock
Copy link

lock bot commented Jun 3, 2018

This thread has been automatically locked.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 3, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

No branches or pull requests

7 participants