katzer / cordova-plugin-local-notifications

Cordova Local-Notification Plugin
Apache License 2.0
2.57k stars 1.76k forks source link

phonegap-plugin-push notifications no longer received after installing cordova-plugin-local-notifications #1626

Closed karlbohlmark closed 1 month ago

karlbohlmark commented 6 years ago

Thanks for a nice plugin! It does exactly what I need (and more), however I need to still be able to receive push notifications but after installing this plugin my callback for the 'notification' event from the phonegap-plugin-push plugin is no longer called. Is this expected?

Your Environment

Expected Behavior

phonegap-plugin-push should still dispatch notification events

Actual Behavior

phonegap-plugin-push no longer dispatches notification events

Steps to Reproduce

1) Create an app using phonegap-plugin-push and listen for 'notification' events. 2) Verify that the 'notification' events are dispatched when push notification events are sent to the device 3) install cordova-plugin-local-notifications 4) Send push notifications to the device

Context

I wanted to use the cordova-plugin-local-notifications to show iOS notifications when push notifications are received when in foreground.

Debug logs

2018-06-19 16:22:01.176937+0200 TaskRunner Pro[1460:1117588] Push Plugin VoIP missing or false 2018-06-19 16:22:01.177356+0200 TaskRunner Pro[1460:1117721] Push Plugin register called 2018-06-19 16:22:01.177426+0200 TaskRunner Pro[1460:1117721] PushPlugin.register: setting badge to false 2018-06-19 16:22:01.177450+0200 TaskRunner Pro[1460:1117721] PushPlugin.register: clear badge is set to 0 2018-06-19 16:22:01.177475+0200 TaskRunner Pro[1460:1117721] PushPlugin.register: better button setup 2018-06-19 16:22:01.177817+0200 TaskRunner Pro[1460:1117721] FCM Sender ID (null) 2018-06-19 16:22:01.177855+0200 TaskRunner Pro[1460:1117721] Using APNS Notification 2018-06-19 16:22:01.226741+0200 TaskRunner Pro[1460:1117588] Push Plugin register success: <>

but then nothing is logged when I send push notifications

chickenbeef commented 6 years ago

I am experiencing the same.

iOS 11.4 Cordova 8.0.0 Platform Version 4.5.4 0.9.0-beta.3

mohamedsharaf commented 6 years ago

same here i hade to remove the plugin

svenkin commented 6 years ago

They aren't compatible on ios atm. See this issue

ddralves commented 6 years ago

So this issue exists not in this plugin but instead in the https://github.com/phonegap/phonegap-plugin-push

The issue lies in the fact that this local notifications plugin makes use of UNUserNotifications delegate instead of the Application delegate used by the phonegap-plugin-push.

To get around this, you will need to update the latest phonegap-plugin-push release which you can see here: https://github.com/phonegap/phonegap-plugin-push/releases

This will ensure that you are able to also "catch" the notifications and the payload using the phonegap-plugin-push.

This local notifications plugin is actually written correctly as it calls the main delegate to ensure that other native layers are able to make use of the UNUserNotification delegate methods:

[_delegate userNotificationCenter:center willPresentNotification:notification withCompletionHandler:handler];

This is why, when updating to the latest phonegap plugin version for push notifications, everything should work as per usual.

I hope this helps everyone!

mohamedsharaf commented 6 years ago

i tested with latest version problem with ios still exist

Tawpie commented 6 years ago

@ddralves just confirming before I go through the hassle of installing the latest phonegap-plugin-push with all of its breaking changes, Firebase and reliance on cocoa pods…

You are getting push notifications with phonegap-plugin-push v2.2.3 (and of course, this plugin!)?

bitdistrict commented 6 years ago

We tried to install the phonegap-push-notifications plugin directly from github becouse we saw the commit https://github.com/phonegap/phonegap-plugin-push/commit/a70a118dcbc6d8e860cf79890e2ab84bcdf141ba which changes to UNUserNotification as @ddralves sayed but this commit was after the last pushed version.

But still we are unable to get triggered notifications in foreground if we have also this cordova plugin local notifications installed... So Meeh

ddralves commented 6 years ago

Hi @Tawpie what version of the phonegap-push-plugin are you currently using?

I was using 2.1.2 and upgrading to 2.2.3 worked fine for me.

@bitdistrict It is very strange that using the release version 2.2.3 still did not resolve the issues for you.

Are you able to share your code where you subscribe to this plugin?

Tawpie commented 6 years ago

@ddralves I'm still using phonegap-plugin-push (gasp) 1.8.4. I've been reluctant to move 'up' due to the breaking changes in Android 7+. I'll have to bite the bullet soon enough though. The forced move to Firebase will be what kicks me over the line.

ddralves commented 6 years ago

@Tawpie Ah ok I see. I think what you could try is the following fork of the phonegap plugin (https://github.com/entersekt/phonegap-plugin-push/commit/0242b57c4b6fd5ab3bbefadb1924528d0ec4d188) That exact commit is a special version of version 2.1.2 but without the Android 7 breaking changes. So all the iOS UNUserNotificationCenter changes are implemented and working.

If you add the plugin from that git repo you should be able to get iOS working without breaking Android.

Otherwise a suggestion would be to fork the phonegap-plugin-push plugin and edit the version 1.8.4 to also only change the iOS native code to include the UNUserNotificationCenter delegates for getting remote notifications to work. I hope that helps :)

suau commented 6 years ago

I'm still seeing the same issue with these two versions:

cordova-plugin-local-notification 0.9.0-beta.2
phonegap-plugin-push 2.2.3
ddralves commented 6 years ago

Hi @suau

If you wouldn’t mind, please post code snippets of your implementation of the plugins? How you instanciaste and use them.

vigneshsosu commented 6 years ago

I'm also facing the same issue,

phonegap-plugin-push 2.1.3 cordova-plugin-local-notification 0.9.0-beta.2

could you pls help me ?

here you can see some snippets


 var push = PushNotification.init({
            ios: {
                alert: "true",
                badge: "true",
                sound: "true"
            }
        });
        push.on('registration', function (data) {
                console.dir(data);
            });
        push.on('notification', function (data) {
                console.dir(data);
                if( data.additionalData.foreground ){
                    cordova.plugins.notification.local.schedule({
                        title: data.title,
                        text: data.message,
                        foreground: true
                    });
                    cordova.plugins.notification.local.on("click", function(evt){
                        console.dir(evt);
                    }, data);
                    return; 
                }
            });
        push.on('error', function (err) {
                console.dir(err);
            });

push.on('notification' not triggered any events, even my app is in both background and foreground state but it is working fine, If I removed your plugin from my app, this is weird

I had tried to find one solution for this issue by tracking your's issues list Still I unable to find any way to fix this, pls do the needful Thanks

Tawpie commented 6 years ago

you might try downgrading the phonegap-plugin-push to 1.8.4. I use that along with local notifications beta-3 (three!, not 2) and can receive push notifications and local notifications.

vigneshsosu commented 6 years ago

@Tawpie Thanks for your suggestion, But still I didn't got any improvment can you pls share your sample app which will have both phonegap-push and local-push-notification plugin ?

this will be the big help for a peoples, who all are like me

and FYI: I'm using new latest cordova -8

and here my plugin list


cordova-plugin-badge 0.8.7 "Badge"
cordova-plugin-device 2.0.2 "Device"
cordova-plugin-inappbrowser 3.0.0 "InAppBrowser"
cordova-plugin-local-notification 0.9.0-beta.3 "LocalNotification"
cordova-plugin-whitelist 1.3.3 "Whitelist"
phonegap-plugin-push 1.8.4 "PushPlugin"
My package.json

{
    "name": "xxxxxx",
    "displayName": "xxxxxx",
    "version": "1.0.0",
    "description": "xxxxxx",
    "main": "index.js",
    "author": "xxxxxx@xxxxxx.com",
    "license": "Apache-2.0",
    "dependencies": {
        "cordova-android": "^7.0.0",
        "cordova-browser": "^5.0.4",
        "cordova-ios": "^4.5.5",
        "cordova-plugin-badge": "^0.8.7",
        "cordova-plugin-device": "^2.0.2",
        "cordova-plugin-inappbrowser": "^3.0.0",
        "cordova-plugin-local-notification": "^0.9.0-beta.3",
        "cordova-plugin-whitelist": "^1.3.3",
        "phonegap-plugin-push": "^1.8.4"
    },
    "cordova": {
        "plugins": {
            "cordova-plugin-whitelist": {},
            "phonegap-plugin-push": {
                "SENDER_ID": "YYYYYYYYYYY"
            },
            "cordova-plugin-local-notification": {},
            "cordova-plugin-inappbrowser": {}
        },
        "platforms": [
            "browser",
            "android",
            "ios"
        ]
    }
}
My config.xml

<?xml version='1.0' encoding='utf-8'?>
<widget id="com.xxxxx.xxxxx" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
    <name>XXXXXX</name>
    <description>
        XXXXXX
    </description>
    <author email="XXXXXX@XXXXXX.com" href="#">
        XXXXXX
    </author>
    <content src="index.html" />
    <plugin name="cordova-plugin-whitelist" spec="1" />
    <access origin="*" />
    <allow-intent href="http://*/*" />
    <allow-intent href="https://*/*" />
    <allow-intent href="tel:*" />
    <allow-intent href="sms:*" />
    <allow-intent href="mailto:*" />
    <allow-intent href="geo:*" />
    <allow-navigation href="http://*/*" />
    <allow-navigation href="https://*/*" />
    <platform name="android">
        <allow-intent href="market:*" />
        <icon density="ldpi" src="res/icon/android/icon-36-ldpi.png" />
        <icon density="mdpi" src="res/icon/android/icon-48-mdpi.png" />
        <icon density="hdpi" src="res/icon/android/icon-72-hdpi.png" />
        <icon density="xhdpi" src="res/icon/android/icon-96-xhdpi.png" />
        <icon density="xxhdpi" src="res/icon/android/icon-144-xxhdpi.png" />
        <icon density="xxxhdpi" src="res/icon/android/icon-192-xxxhdpi.png" />
    </platform>
    <platform name="ios">
        <allow-intent href="itms:*" />
        <allow-intent href="itms-apps:*" />
        <preference name="DisallowOverscroll" value="true" />
        <icon height="57" src="res/icon/ios/icon-57.png" width="57" />
        <icon height="114" src="res/icon/ios/icon-57-2x.png" width="114" />
        <icon height="180" src="res/icon/ios/icon-60-3x.png" width="180" />
        <icon height="60" src="res/icon/ios/icon-60.png" width="60" />
        <icon height="120" src="res/icon/ios/icon-60-2x.png" width="120" />
    </platform>
    <preference name="DisallowOverscroll" value="true" />
    <plugin name="phonegap-plugin-push" spec="1.8.4">
        <variable name="SENDER_ID" value="YYYYYYYYY" />
    </plugin>
    <plugin name="cordova-plugin-local-notification" spec="^0.9.0-beta.3" />
    <plugin name="cordova-plugin-inappbrowser" spec="^3.0.0" />
    <engine name="browser" spec="^5.0.4" />
    <engine name="android" spec="^7.0.0" />
    <engine name="ios" spec="^4.5.5" />
</widget>

pls do the needfull Thanks

Tawpie commented 6 years ago

@vigneshsosu I hate to say "it's too much work to share my sample app", but it is. The app is quite large. I should clarify that I do not worry about getting push notifications while my app is in the foreground. I know there are use cases for that, but I try to avoid distracting the user while they're using the app. So if push notifications while in the foreground is the actual need, I can't help.

As an information point, I think that in the past iOS suppressed push notifications that arrive while the app is in foreground because Apple has decided that interrupting the user is something they won't do. This suppression was done at the OS level. I don't know if they've changed anything or not.

I'm sorry if I misled you!

marianoaptly commented 5 years ago

It would be great if this issue could be fixed, so we can show notifications both in back and foreground when using the library along with push notifications.

Thanks in advance!

aliraza-dev commented 5 years ago

M having weird issue with phonegap-push. I can receive notifications on android 7 and above but on 6 and below, On some versions I can see icon without tune and on others, I can't even see icon, vibration and tune are absent too, But i can notification in notification panel. Any guidance?