IOS push notification "forceShow": "true"

Hi ,

I’m using plugin for push notification

cordova plugin add phonegap-plugin-push --variable SENDER_ID=“xxxxx”

i getting push notification if app is in foreground for ios device(i checked with version 9.3.5 , 10 and above) …but i want to show that in shade . For android we have “forceShow”: “true” is there anything for ios.
my front end code is here .

       var push = PushNotification.init({
                "android": {
                    "senderID": "xxxxx",
                    "icon": "notify",
                    "iconColor": "#204057",
                    "forceShow": "true"
                },
                "ios": {
                    "alert": "true",
                    "badge": "true",
                    "sound": "true"
                }
            });

            push.on('registration', function(data) {
               alert(data);
            });

            push.on('notification', function(data) {
                alert(data);
            });

            push.on('error', function(e) {
            });
1 Like

Hi!

We are facing the same problem :frowning2:

Did you finally solve this, @Maheshvy?

Thanks in advance!

What does that moean?
What does “forceShow” do on Android exactly?

Hi @Sujan12

“forceShow” property in Android works as follows, according to the Cordova Push Plugin Documentation :

Controls the behavior of the notification when app is in foreground. If true and app is in foreground, it will show a notification in the notification drawer, the same way as when the app is in background (and on(‘notification’) callback will be called only when the user clicks the notification). When false and app is in foreground, the on(‘notification’) callback will be called immediately.

In my case, the on('notification') callback makes a request and then a state change in the ui-router, so with the forceShow set to true, I just see a normal notification and it’s user’s choice to click on it and with that executing the callback.

In Android this is working as desired, if you are in a view and you receive a notification, if the user clicks on it it will be forced to change the state in the ui-router

In iOS user doesn’t have that choice(the forceShow option), and the on('notification') callback is always executed and if the user is with the app in foreground, at the moment the notification is received there is a state change.

Thanks!

I don’t think this concept of “if I have the app open and get a notification, only show it on the OS level” exists in iOS - the moment you open the app, all already received and then received notifications while the app is open are handled by the app directly - and the “OS level” notification stuff (notification center basically) is bypassed.

But I am sure you could just handle the notification, show the user inside the app that some “notification event” was pushed onto a stack, and by clicking e.g. a button he can see this notifications and accept them. Think of Whatsapp or Facebook messages inside the Facebook app.

1 Like

Thank you for your response @Sujan12 . Finally we have created a modal for handling the notification in IOS.

Ok, so you are doing it manually in the app, right?

Yes. Here is the piece of code for this:

//push notification plugin configuration
var push = PushNotification.init({
  android: {
    senderID: ConstantsValues.SENDER_ID,
    icon: "icon",
    forceShow: true
  },
  ios: {
    alert: "true",
    badge: "true",
    sound: "true",
    icon: "icon"
  },
});

//push plugin registration event
push.on('registration', function (data) {
  console.log('Register ID: ' + data.registrationId);
  var deviceRequest = {
    registerId: data.registrationId,
    deviceType: $rootScope.isAndroid ? 'ANDROID' : 'IOS',
    deviceId: window.device.uuid
  };
  //Get request to register device to our server
  CustomService.notificationPush(deviceRequest); 
});

//When click notification in bar or a notification is received in foreground
push.on('notification', function (data) {
  if($rootScope.isIOS && data.additionalData.foreground) {
    //Show modal to user to give him/her choice to travel to the notification state
    //custom Modal Service
    ModalService 
      .show('notificationModal.html', 'NotificationModalController', data).then(function (result) {
        if(result){
          //if user click SHOW NOTIFICATION on Modal 
          getDetailNotification(data);
        }
      });
  } else {
    //Android background or foreground(with forceShow: true) OR iOS background
    getDetailNotification(data);
  }
});
1 Like