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

on("notification") not called when iOS app in foreground #2547

Closed
rudiminty opened this issue Sep 13, 2018 · 5 comments
Closed

on("notification") not called when iOS app in foreground #2547

rudiminty opened this issue Sep 13, 2018 · 5 comments

Comments

@rudiminty
Copy link

When I receive a push notification on iOS while the app is in the foreground, the on("notification") function should be triggered.

When the app is in the foreground, the push notification is received and displayed as a normal notification in the notification centre and does not trigger the on("notification") function.
When I select the notification however, it does trigger the on("notification") function with the push notification payload.
The behaviour works as expected on Android.

When I run my app using cli-6.5.0 on the plugin version 1.11.1 then it works as expected, but not when using cli-7.5.0 with plugin version 1.11.1 or 2.1.2.

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

cli-7.1.0 (iOS 4.5.4 / Android 6.3.0)

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

Testing on iPhone 6s with iOS 11.1

Plugin version

plugin versions tested 1.11.1 & 2.1.2 with the same issue.

Sample Code that illustrates the problem

    try {
        push = PushNotification.init({
            "android": {
                "senderID": "XXX",
                "forceShow": false,
                "sound": true,
                "vibrate": true
            },
            "ios": {
                alert: true,
                badge: true,
                sound: true
            },
            "windows": {}
           
        });
    } catch (exc) {
        mobile.alert('Error Initializing Push Notifications: ' + exc.message);
        push = false;
    }
        if (push) {
            push.on("registration", function (data) {
                // registration info here
            });

            push.on("error", function (e) {
                mobile.alert("Push Notification Error: " + e.message);
            });

            push.on("notification", function (data) {
                mobile.alert('NOTIFICATION [' + JSON.stringify(data) + '] processing...');
                // logic goes here
            });

        }
@rudiminty
Copy link
Author

rudiminty commented Sep 14, 2018

With some more tests, I actually notice that when the app is open in the foreground, and a push notification is received and I select the message as it peaks from the top of the screen, the data being passed to the on("notification") function even indicates "foreground":true but on("notification") is not fired until I select the message.

@umeshiyer
Copy link

rudiminty
Do you have katzer's local notification plugin also included in your project?

@macdonst
Copy link
Member

@rudiminty you shouldn't see the notification in the shade when the app is in the foreground. As @umeshiyer asked are you using the local notification plugin?

@rudiminty
Copy link
Author

Thanks for the responses.

@umeshiyer , no not using local notification plugin.

I have however by means of elimination noticed that the plugin cordova-plugin-mauron85-background-geolocation is most probably the cause with this specific issue perhaps contributing: mauron85/react-native-background-geolocation#268 (comment)

@lock
Copy link

lock bot commented Oct 19, 2018

This thread has been automatically locked.

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

No branches or pull requests

3 participants