ostownsville / cordova-plugin-fcm

Google FCM Push Notifications Cordova Plugin
21 stars 17 forks source link

Data messages iOS #19

Open ironbone opened 6 years ago

ironbone commented 6 years ago

In my test app the Notification messages are working well. I have a problenm with Data messages. So this is the situation

  1. When app is in fordeground I can obtain them (ios android) fast
  2. When application is workin in background then when I set the app to foreground I obtain the mesage by VERRY often it takes 1-2 houres (iOS 11.0.3, android). BUT when I use the https://github.com/arnesson/cordova-plugin-firebase then (on android) it works very fast.
  3. The application is closed. I never get the notification on iOS 11.0.3. I seams that I get it on android but it takes houres. On Android with https://github.com/arnesson/corordova-plugin-firebase it works fast.

I know that this is the problem od low prioryty of data messages. But why it is possible to deliver them fast with corordova-plugin-firebase in android and the plugins are very simmilar.

Every thing is well configured in my application because the Notifications are working very well.

CowboyCode commented 6 years ago

We looking at the moment at android updates, I didn't have myself problems with ios 11.03 but it is in work.

ironbone commented 6 years ago

Thanx. I will do more test on a very simple app. I will let you know.

ironbone commented 6 years ago

Hello here are the results of my test on ios 11.0.3. On android everything looks (for me) ok.

I use ionic, with the example from ionic doc (I additionnaly add one more subscription), I do not unsubscribe at all. Here is the main part om my code:


                 this.fcm.getToken().then(token => {
                        console.log("+++GET Token: " + token);
                    })

                    this.fcm.onNotification().subscribe(data => {
                         alert("Notification");

                    })

                    this.fcm.onTokenRefresh().subscribe(token => {
                        console.log("+++Refresh Token: " + token);
                    })

                    this.fcm.subscribeToTopic('marketing');
                    this.fcm.subscribeToTopic('marketing2');

For data messages I use the following: curl -X POST --header "Authorization: key=HERE_IS_MY_KEY" --Header "Content-Type: application/json" https://fcm.googleapis.com/fcm/send -d '{ "to": "/topics/marketing","priorty": "normal","content_available": true,"data": { "message": "This is a Firebase25"}}' For Notification messages I use https://cordova-plugin-fcm.appspot.com and send messages to the topic marketing.

I instal the application insing xCode. After installing I disconect my device from the computer and restart the application. Before every test I restart the application. Before instaling a new version, with new settings, I uninstall the application.

In xCode setting I set on in Capabilities: Push Notification, and from Background Modes: Remote Notification and Background fetch.

Every time when I start the application I allow Push Notification.

The behaviour of the application depends of the value of FirebaseAppDelegateProxyEnabled so I will present two test with different settings of FirebaseAppDelegateProxyEnabled in xCode Project -> Info


  1. FirebaseAppDelegateProxyEnabled not used or set to YES

1.1 If the Data Message is send when Application is in foreground - I get the notification fast Application is in background - I get the notification, it takes sometimes time but is ok Application is not working - Afte starting the application the is NO notfication (even after 12 hours) PROBLEM

1.2 If the Notification message is send when Application is in foreground - I get the notification fast, but twice (little PROBLEM) Application is in background - The notification is presented, after clickin on it I go to my application, there I get the notification Application is not working - The notification is presented, after clickin on it I go to my application, but there is NO notification (PROBLEM)


  1. FirebaseAppDelegateProxyEnabled is set to NO

2.1 If the Data Message is send when Application is in foreground - I get the notification fast Application is in background - I get the notification, it takes sometimes time but is ok Application is not working - After starting the application the is NO notfication (even after 12 hours) PROBLEM

2.2 If the Notification message is send when Application is in foreground - I get the notification fast Application is in background - The notification is NOT presented, BUT when I go to my application, there I get the notification (PROBLEM) Application is not working - The notification is NOT presented. When I go to my application, there NO notification (PROBLEM)

chrisjpalmer commented 6 years ago

Hi @ironbone.

FirebaseAppDelegateProxyEnabled needs to be set to YES. The plugin is designed with this feature in mind. Essentially what it does is allows Firebase to connect to the APNS callbacks in Objective C and wrap them. If you disable it, the notification will not display. They will still cause the notification to propagate through the onNotification event because Firebase has a second channel (private direct connection to Firebase which bypasses apple) through which notifications can be propagated in the case of data only notifications OR when APNS is unavailable.

You are not the first to identify issues with iOS 11. We are very sorry that this does not work for everyone yet. I am currently unable to test natively BUT will be able to in a few days time. Prior to now I have not had an iOS 11 device to test.

It seems to me that the problems people are identifying are:

@CowboyCode and @ironbone can you confirm?

ALSO... We have removed support for this: https://cordova-plugin-fcm.appspot.com It uses some predefined topics which the old plugin used to subscribe automatically too. However this is not supported in our plugin. Therefore, the best way to test is to use the Firebase console.

CowboyCode commented 6 years ago

I have just upgraded the firebase ios sdk to version 4.4.0

Three fcm changes

Improved logging of notification opens, by swizzling additional UNUserNotificationCenterDelegate method.

Improved the handling of unimplemented UNUserNotificationCenterDelegate methods, when swizzling is enabled.

Improved support for working in shared Keychain environments.

https://firebase.google.com/support/release-notes/ios

chrisjpalmer commented 6 years ago

Thats brilliant.

This may fix the problems people are experiencing. But of course it will still need testing. I will be testing over the week.

Method Swizzling is the objective-C coding feature which FirebaseAppDelegateProxyEnabled uses

Chris

On 23 Oct 2017, at 5:23 pm, Oliver Blum notifications@github.com wrote:

I have just upgraded the firebase ios sdk to version 4.4.0

Three fcm changes

Improved logging of notification opens, by swizzling additional UNUserNotificationCenterDelegate method.

Improved the handling of unimplemented UNUserNotificationCenterDelegate methods, when swizzling is enabled.

Improved support for working in shared Keychain environments.

https://firebase.google.com/support/release-notes/ios https://firebase.google.com/support/release-notes/ios — You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/ostownsville/cordova-plugin-fcm/issues/19#issuecomment-338558880, or mute the thread https://github.com/notifications/unsubscribe-auth/AcaUOxQKQPnhe8T-XZxc8x8YvcsgeXsJks5svDDSgaJpZM4P9ibW.

ironbone commented 6 years ago

Afrer test there is almost no progress: 1.1 If the Data Message is send when Application is in foreground - I get the notification fast Application is in background - I get the notification, it takes sometimes time but is ok Application is not working - Afte rstarting the application the is NO notfication (even after 6 hours) PROBLEM

1.2 If the Notification Message is send when Application is in foreground - I get the notification fast,and now only one time (PROGRESS) Application is in background - The notification is presented, after clickin on it I go to my application, there I get the notification Application is not working - The notification is presented, after clickin on it I go to my application, but there is NO notification (PROBLEM)

chrisjpalmer commented 6 years ago

Hi there.

Reviewing the issues above:

  1. Tapping a notification from the notification centre does not fire the callback

  2. Data only notifications sent in the background are: a) Not being received in the background immediately b) Not being received upon app reopen

I think we have managed to solve both 1 and 2.

Problems However you said that there are still problems when the application is completely closed AND you want to receive the notification upon open. I think the plugin code may be working BUT cordova is not ready to feed the events to javascript.

To prove this, I would perform the test where you open the app and expect the notification. Then note the time that you did this. Plug your device into XCode and use the devices feature to obtain the logs. Go to the logs around the time you performed the test. You should see one of the callbacks being fired in the logs by the internal plugin code:

I designed the plugin so that anytime one of these functions is hit, you see a comment:

Also note that DidFinishLaunchingWithOptions is the callback which gets fired after the plugin is initialised.

If you see one of these being fired, then the plugin is working well BUT its not able to reach cordova because its too early. In this case, I need to get coding to sort this problem out.

Chris

ironbone commented 6 years ago

Data only notifications sent in the background are: OK - but it takes realy time to get it -15-30 minuts, even If we reopen the application every minut.

I will do the test described above by chrisjpalmer. I will let you know.

ironbone commented 6 years ago

After some test I see the following. When the application is not working and I send a Data Notyfication I get the following:

SpringBoard(ApplePushService)[55] : Delivering message from apsd: 1698829173 SpringBoard(ApplePushService)[55] : responding with an ack for message with guid SpringBoard(ApplePushService)[55] : making delegate () calls to deliver message 1698829173 for topic SpringBoard(ApplePushService)[55] : calling connection:didReceiveIncomingMessage: SpringBoard(ApplePushService)[55] : returned from connection:didReceiveIncomingMessage: SpringBoard(UserNotificationsServer)[55] : Received incoming message on topic lu.lllc.fcm at priority 1 SpringBoard(UserNotificationsServer)[55] : [lu.lllc.fcm] Received remote notification request D827-6C29 [ hasAlertContent: 0, hasSound: 0 hasBadge: 0 hasContentAvailable: 1 hasMutableContent: 0 ] SpringBoard(UserNotificationsServer)[55] : [lu.lllc.fcm] Deliver push notification request D827-6C29 SpringBoard(UserNotificationsServer)[55] : [lu.lllc.fcm] Passing content-available push to Duet SpringBoard(DuetActivityScheduler)[55] : SUBMITTING: SpringBoard(UserNotificationsServer)[55] : Ignoring notification with no alert, sound or badge (lu.lllc.fcm): D827-6C29 SpringBoard(UserNotificationsServer)[55] : [lu.lllc.fcm] Not saving push notification D827-6C29 to store [ error=Error Domain=UNErrorDomain Code=1401 "Notification has no user-facing content" UserInfo={NSLocalizedDescription=Notification has no user-facing content} ] dasd(DuetActivitySchedulerDaemon)[150] : Submitted Activity: com.apple.pushLaunch.lu.lllc.fcm:FD2763 dasd(DuetActivitySchedulerDaemon)[150] : Daemon Canceling Activities: {( com.apple.pushLaunch.lu.lllc.fcm:FD2763 )} dasd(DuetActivitySchedulerDaemon)[150] : CANCELED: com.apple.pushLaunch.lu.lllc.fcm:FD2763 ! dasd(DuetActivitySchedulerDaemon)[150] : Removing a launch request for application by activity apsd[102] : Looking up connection on peer: 21e329f0 found apsd[102] : informed that acknowledges incoming message with guid apsd[102] : Removing incoming message with guid apsd[102] : APSMessageStore - APSIncomingMessageRecordDeleteMessageForGUID apsd[102] : _schedulePendingWorkUpdate apsd[102] : Submitted metric: 0x130008 succeeded? YES SpringBoard(DuetActivityScheduler)[55] : cancelActivities: 1 activities were not found: analyticsd[90] : [] no observers; dropped. analyticsd[90] : [] no observers; dropped.

It seams that the notification arives but I see the problem here: dasd(DuetActivitySchedulerDaemon)[150] : CANCELED: com.apple.pushLaunch.lu.lllc.fcm:FD2763 ! dasd(DuetActivitySchedulerDaemon)[150] : Removing a launch request for application by activity

ironbone commented 6 years ago

I have instaled iOS 11.1 and this is a nightmare. The data notifications works but from time to time. After restarting the device it seams to be ok. After same time they stop to work.

CowboyCode commented 6 years ago

I haven't upgraded yet, will do that soon. Firebase will upgrade the sdk soon after iphone x changes, I guess.

Did you do the Xcode upgrade?

ironbone commented 6 years ago

sorry, after more testing it is not so bad. But I see no progress. Still no notification when app is closed. I will keep testing ;) I use Xcode 9.1 - so it is upgraded

CowboyCode commented 6 years ago

I just tested it through, see below

ionic/cli-utils  : 1.15.2
ionic (Ionic CLI) : 3.15.2

global packages:

cordova (Cordova CLI) : 7.1.0 

local packages:

Cordova Platforms : android 6.2.3 ios 4.5.2
Ionic Framework   : ionic1 1.3.2

System:

Android SDK Tools : 26.1.1
ios-deploy        : 1.9.2 
Node              : v6.11.4
npm               : 3.10.10 
OS                : macOS Sierra
Xcode             : Xcode 9.1 Build version 9B5

Tested Iphone 7 - IOS 11.3

fresh install from (removed and added new) cordova plugin add https://github.com/ostownsville/cordova-plugin-fcm.git

`

luigi37 commented 6 years ago

All, am I right in saying that this case:

ironbone commented 6 years ago

I can confirm this. App not running -> Message NOT received (also not on open app) On Android it works ok. One remark about iOS 11.1. There is a big problem with notifications. They work during some time and then not. Restarting of the device does not help. On my device it helps "Reset Network Settings" and then restart.

ironbone commented 6 years ago

Sometimes some notifications are lost. And then I get the next notifications. On iOS 10.3 I get the notifications very fast (sometimes faster then on Android )

luigi37 commented 6 years ago

Sometimes some notifications are lost

This is really scaring considering my App might rely on a single notification event and I understand there is no way to understand if the notification was received...

chrisjpalmer commented 6 years ago

Okay guys thanks very much for your hard work. I think this can be fixed by having a bit of code which waits until javascript registers its event handler before dispatching the notification. I am sure that what is happening is that the push plugin is receiving the APNS message but dispatching it too early and thus the event will not make its way to the application.

As for the unreliability factor of iOS 11, I cannot confirm this as I have had success this morning testing on my iPhone on iOS 11.1. There have been no blips. I will report if there are.

Thanks

chrisjpalmer commented 6 years ago

Im looking to push up a commit by next wednesday. I think I have a solution to this issue.

ironbone commented 6 years ago

iOS 11.1. Yes it works but sometime stops. For example my app is been working well during the las 24 hours. But before I needed to Reset Network Settings. So I'm not even be able to repeat the problematic situation.

chrisjpalmer commented 6 years ago

Hi guys. This definitely needs ongoing testing. Gonna be honest, im doing this on the side so I have limited time. Please be patient we will do what we can. I have pushed an untested, uncompiled fix which I hope resolves the issue where the notification doesn't come through on the app on app load for iOS.

Its not on the main branch. Its on the dev-ios11 branch. Feel free to give it a test in the mean time you might be able to speed this up for us. I will come back to it next week and hopefully get a fix out.

chrisjpalmer commented 6 years ago

Also please test out my testing project for Cordova Plugin FCM at https://github.com/chrisjpalmer/cordova-plugin-fcm-test

This should be a great asset to the plugin and help identify problems easily. You will need Ionic

luigi37 commented 6 years ago

Hey Chris, thanks for the hard work on this! Much appreciated.

chrisjpalmer commented 6 years ago

Hi Guys.

Good news. I think I have squashed this one. My fix (3.0.3) is not on main branch as I have more work to do until its all final. Please see latest commit on branch dev-fixes.

Also you can easily test / verify its working using my testing project: https://github.com/chrisjpalmer/cordova-plugin-fcm-test/tree/3.0.3

However, I did find that tapped notifications on Android do not work and this will need some bug finding.

luigi37 commented 6 years ago

Hi Chris, thanks! Do you mean your fix (3.0.3) disabled for some bug Android Tap notification or any version?

chrisjpalmer commented 6 years ago

3.0.3 doesn’t introduce the Android bug. Its in all versions. I just discovered it while testing.

Chris

On 19 Nov 2017, at 7:38 pm, luigi37 notifications@github.com wrote:

Hi Chris, thanks! Do you mean your fix (3.0.3) disabled for some bug Android Tap notification or any version?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/ostownsville/cordova-plugin-fcm/issues/19#issuecomment-345500888, or mute the thread https://github.com/notifications/unsubscribe-auth/AcaUO7GeZ6yz7yTdxT43NlHYlIEzvcRWks5s3-jqgaJpZM4P9ibW.

luigi37 commented 6 years ago

Hi Chris. In which case it did not work?

chrisjpalmer commented 6 years ago

Correct, it appears that when you tapped a notification on an Android devices the js callback was not invoked at all. This feature was meant to work but never did. I am working on this fix now too.

On 20 Nov 2017, at 9:39 am, luigi37 notifications@github.com wrote:

Hi Chris. In which case it did not work?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/ostownsville/cordova-plugin-fcm/issues/19#issuecomment-345556123, or mute the thread https://github.com/notifications/unsubscribe-auth/AcaUOwuMVAnAeA8gAmRlz3aaG9kB5F-Aks5s4K4MgaJpZM4P9ibW.

luigi37 commented 6 years ago

Ummmm... Just checked on android 7.0 and it works when app is open, in background and closed...

chrisjpalmer commented 6 years ago

Hi Luigi

Thats strange I was getting problems when I tested last time. I will test again.

Thanks

On 20 Nov 2017, at 9:46 am, luigi37 notifications@github.com wrote:

Ummmm... Just checked on android 7.0 and it works when app is open, in background and closed...

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/ostownsville/cordova-plugin-fcm/issues/19#issuecomment-345556635, or mute the thread https://github.com/notifications/unsubscribe-auth/AcaUO0hWNKbXa-_0llB02-QLFFKl6XDoks5s4K-qgaJpZM4P9ibW.

luigi37 commented 6 years ago

Hi all, Android looks working properly... I have checked app closed, app in background and app in foreground and all is fine. In iOS I receive notification only in background and the onNotification NEVER gets called BUT I'm using master branch.

To test the dev-fixes branch I should remove FCM plugin and re-add through cordova plugin add https://github.com/ostownsville/cordova-plugin-fcm/tree/dev-fixes --save cordova plugin add https://github.com/ostownsville/cordova-plugin-fcm#dev-fixes --save

also using Android 6.2.3 Ios 4.5.0

Thanks Luigi

luigi37 commented 6 years ago

Corrected the post above

luigi37 commented 6 years ago

Tried as below:

Installed platforms: android 6.2.3 ios 4.5.0

cordova -v 7.1.0

Ios: Push Notification capability enabled Backgroun Notification capability enabled

Not sure about XCode (I'm on a cloud server for Mac, but if needed I can check) XCode 9.1

cordova plugin cordova-google-api-version 0.0.1 "cordova-google-api-version" cordova-plugin-device 1.1.6 "Device" cordova-plugin-dialogs 1.3.4 "Notification" cordova-plugin-fcm 3.0.3 "FCMPlugin" cordova-plugin-globalization 1.0.8 "Globalization" cordova-plugin-inappbrowser 1.7.2 "InAppBrowser" cordova-plugin-splashscreen 4.0.3 "Splashscreen" cordova-plugin-whitelist 1.3.0 "Whitelist" es6-promise-plugin 4.1.0 "Promise"

On Android all ok. On iOS NOT getting onNotification call if app is in foreground and clicking on background notification doesn't rise the event...

luigi37 commented 6 years ago

Guys, apologies on the comment about iOS above. I realized it was a mistake in my code. On Mac iOS emulator foreground works. I'm going to check soon on real device but I trust it was just my mistake. Sorry!

blumanski commented 6 years ago

@uigi37 no worries you are doing a great job with testing, thanks mate

luigi37 commented 6 years ago

Thanks :-) Ok, also on iOS 5S with 11.1.2 real device it works in foreground!

Thanks guys!

chrisjpalmer commented 6 years ago

Okay I guys I have merge dev-fixes. Can we close this issue?

luigi37 commented 6 years ago

All test are positive for me. I think we can close this

ironbone commented 6 years ago

But what with the message when the application is closed? Or maybe we will get it never working because this is a feature of firebase?

luigi37 commented 6 years ago

In my tests, I do get the notification issued when app is closed. When I click on the notification, iOS opens the app and call the onNotification event.

Anyway please note that the structure of the request sent to firebase should be similar to this (PHP):

        $headers = array
                    (
            'Authorization: key=' . API_ACCESS_KEY,
            'Content-Type: application/json'
        );
    $msg = array
        (                    
            'title' => $mytitle,
            'body'  => $mybody,
            'sound' =>  $sound, 
                            /*If you want notification sound.
                           Works in Android, must be like "test.mp3" here 
                           and in the App folder like 
                            platforms/android/res/raw/test.mp3
                           I've setup a hook in after_platform_add
                           Not sure how to make it work in iOS
                           it looks like you need a test.caf file in platform/ios folder...  
                          and something like "sound" in "apn" array sent to fcm....
                           */
            'click_action'  => "FCM_PLUGIN_ACTIVITY", 
                            //Must be present for Android
            'icon'  =>   "fcm_push_icon"  
                             //White icon Android resource
        );
    $data = array
        (
            'Var_to_app_1' => $var1,
            'Var_to_app_2' => $var2,
            'Var_to_app_3' => $var3
        );
    $fields = array
        (
            //'to'      => $IDs,  //use 'registration_ids' for TOKENS list
            'registration_ids' => $newId, // TOKENS array
            //'message'     => 'here is a message. message',  
                           //'message' must be excluded to work properly
            'priority'  => 'high',  
            'notification'  => $msg,
            'data' => $data
        );

    $ch = curl_init();
    curl_setopt( $ch,CURLOPT_URL, 'https://fcm.googleapis.com/fcm/send' );
    curl_setopt( $ch,CURLOPT_POST, true );
    curl_setopt( $ch,CURLOPT_HTTPHEADER, $headers );
    curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );
    curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false );
    curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode( $fields ) );
    $resultFCM = curl_exec($ch );
    if ($resultFCM === FALSE) {
                die('Curl failed: ' . curl_error($ch));
            }
    curl_close( $ch );
    $resultFCM = json_decode($resultFCM);

ABSENCE of message seems quite important for all to work properly. notification stuff goes into the Notification panel as title and body of the notication itself. data gets passed to the cordova app

ironbone commented 6 years ago

I am talking about data messages not notification messages.

luigi37 commented 6 years ago

I see. In effect with method above you can get a paylod ('data') delivered together with a notification but I'm not sure how it works with Data only messages. I tend to think that only an open app could get those as it's the notification itself that make the app reopen...

tomek-servlets commented 6 years ago

In android it works without problems - therefore my question.

luigi37 commented 6 years ago

Ok. What is the sequence in Android that you found correct and could you share also the structure of notification (similar to what I did above) ?

tomek-servlets commented 6 years ago

On Android the following works. I start the application. I subscribe to a channel. I close the application (remove from the memory) I send a data message to the channel: curl -X POST --header "Authorization: key=HEREMYKEY" --Header "Content-Type: application/json" https://fcm.googleapis.com/fcm/send -d '{ "to": "/topics/my_channel","priorty": "normal","content_available": true, "collapse_key": "data_update", "data": { "action": "new_data"}}'

I start the application one more time. The application obtains the notification. But it does not work on iOS

luigi37 commented 6 years ago

there is a typo but maybe it's not the issue: ,"priorty": "normal" Will give it a try tonight on my setup