phonegap / phonegap-plugin-push

Register and receive push notifications
MIT License
1.94k stars 1.92k forks source link

Tap on notification when app is in foreground iOS #2608

Open tbeata opened 5 years ago

tbeata commented 5 years ago

Expected Behaviour

Trigger on(notification) handler when tappig notification with app in foreground.

Actual Behavior

Handler get triggered when notification arrived, but it doesn't when tapping on the notification.

Reproduce Scenario (including but not limited to)

I've modified the

Push Plugin didReceiveNotificationResponse: actionIdentifier com.apple.UNNotificationDefaultActionIdentifier, notification: {
    addInfo = "";
    aps =     {
        alert =         {
            body = 1;
            title = 12;
        };
        badge = 1;
        category = "NEW_MESSAGE_CATEGORY";
    };
    body = 1;
    connectionId = 0x8lcanf1v9o;
    "content-available" = 1;
    count = "";
    "gcm.message_id" = 1541164856937801;
    "google.c.a.e" = 1;
    notId = 592244350;
    objId = "relations_fi20060000000525";
    objType = file;
    sound = "";
    surveyID = abcd;
    title = 12;
}
2018-11-02 14:20:59.297775+0100 myFavorites[951:277971] Push Plugin userInfo {
    actionCallback = "com.apple.UNNotificationDefaultActionIdentifier";
    addInfo = "";
    aps =     {
        alert =         {
            body = 1;
            title = 12;
        };
        badge = 1;
        category = "NEW_MESSAGE_CATEGORY";
    };
    body = 1;
    connectionId = 0x8lcanf1v9o;
    "content-available" = 1;
    count = "";
    "gcm.message_id" = 1541164856937801;
    "google.c.a.e" = 1;
    notId = 592244350;
    objId = "relations_fi20060000000525";
    objType = file;
    sound = "";
    surveyID = abcd;
    title = 12;
}
2018-11-02 14:20:59.297888+0100 myFavorites[951:277971] Notification received
2018-11-02 14:20:59.297959+0100 myFavorites[951:277971] Push Plugin key: alert
2018-11-02 14:20:59.298011+0100 myFavorites[951:277971] Push Plugin key: category
2018-11-02 14:20:59.298058+0100 myFavorites[951:277971] Push Plugin key: badge

But the on(notification) handler doesn't get called this time.

Steps to Reproduce

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

iOS 12.0.1

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

Cordova CLI version and cordova platform version

cordova --version                                    8.1.2
cordova platform version iOS                 4.5.5

Plugin version

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

2.2.3 with the above mentioned modification

Sample Push Data Payload

"message": {
                "data": {
                    "content-available": "1",
                    "sound": notificationData.sound,
                    "title": notificationData.title,
                    "body": notificationData.message,
                    "notId": notId,
                    "connectionId": devicePushInfo.serverConnectionId,
                    "objId": notificationData.fileId,
                    "objType":notificationData.fileType,
                    "domainId": notificationData.mainConfigId,
                    "addInfo": notificationData.addData,
                    "surveyID": "abcd"
                },
                "android": {
                    "ttl": "86400s",
                    "data": {
                        "priority": "2"
                    }
                },
                "apns": {
                    "headers": {
                        "apns-priority": "5",
                        "apns-expiration": Math.floor(Date.now() / 1000 + 86400).toString()
                    },
                    "payload": {
                        "aps": {
                            "alert": {
                                "title": notificationData.title,
                                "body": notificationData.message
                            },
                            "category": "NEW_MESSAGE_CATEGORY"
                        }
                    }
                },
                "token": devicePushInfo.deviceToken
            }

Please help me :)

tbeata commented 5 years ago

Any ideas? :) Please, it's really really important.

ghost commented 5 years ago

news about that?

RasimKanca commented 5 years ago

I made similar changes in my code and ran into the same issue. The only thing that solved it for me was to remove the actionCallback key from additionalData in the notificationReceived method. I don't know why this works, if I change the value of actionCallback to a random string, I also do not get the notification event. If I rename the actionCallback key to anything else, I do get the notification event.

I added the following condition above this line to prevent the actionCallback from being added:

} else if ([key isEqualToString:@"actionCallback"]) {
  break;

It would be really interesting to see whether this fix works for others, whether there is a better way to solve it and why it occurs in the first place. Although I do want to reiterate that this problem only occurs when interacting with foreground notifications.

tbeata commented 5 years ago

Hi, Try changing: pushHandler.notificationMessage = userInfo; to pushHandler.notificationMessage = response.notification.request.content.userInfo;

in method:

This worked for me.

tbeata commented 5 years ago

Here's my fork: https://github.com/tbeata/phonegap-plugin-push

RasimKanca commented 5 years ago

That seems to work for same reason, the actionIdentifier isn't added to response.notification.request.content.userInfo. Thanks for the update.