cordova-plugin-firebase
cordova-plugin-firebase copied to clipboard
iOS: Push notifications are shown when in foreground
On iOS Push notifications are shown although the app is in foreground. This bug was introduced in the commit https://github.com/arnesson/cordova-plugin-firebase/commit/06a8b2db25805ff9634f3b00dd9e3dcabf7d7f3e.
As per Apple developer documentation: https://developer.apple.com/documentation/usernotifications/unusernotificationcenterdelegate
func userNotificationCenter(UNUserNotificationCenter, willPresent: UNNotification, withCompletionHandler: (UNNotificationPresentationOptions) -> Void) Asks the delegate how to handle a notification that arrived while the app was running in the foreground.
So the completion handler should be called with completionHandler(UNNotificationPresentationOptionNone);, which doesn't show the Push notification anymore when the app is in foreground.
I think the default behavior of this plugin should be not to show Push notification when in foreground.
I was relieved when they started working as I was not able to get this plugin to work with cordova-plugin-local-notifications; however, you are right that the notifications should not be shown as it was before.
Also getting this issue :(
@maitscha it seems that you have some idea on a fix. Can you fork the repo, make the proposed change and create a pull request? That would also allow others to test the change.
Made a pull request: https://github.com/arnesson/cordova-plugin-firebase/pull/835
@maitscha, looking at the comments on #835 it looks like this bug isn't fixed by that PR. Any other ideas for how to prevent the notifications showing on iOS when the app is in the foreground?
Any updates on this? Still not working properly
We are having the same issue - is there any progress made on this?
I got it working.
Maybe this is helpful for someone: As I already had the plugin installed, I not only had to change PROJECT_ROOT/plugins/cordova-plugin-firebase/AppDelegate+FirebasePlugin.m but also PROJECT_ROOT/platforms/ios/PROJECT_NAME/plugins/cordova-plugin-firebase/AppDelegate+FirebasePlugin.m as changes to the former file are not automatically applied to the build (I guess you have to run cordova prepare ios, but this also removes the platform completely and re-adds it). Now, notifications are working as expected (not shown in foreground).
same issue here. @cremfert what exactly did you change to make it work?
Our team has faced with this bug too. Did someone handle that?
if i rewrite AppDelegate+FirebasePlugin.m: completionHandler(UNNotificationPresentationOptionAlert); to: completionHandler(UNNotificationPresentationOptionNone);
push notifications not appear, no matter if in foreground or in background. please, can anyone tell us how to make it work?
Is this plugin outdated? There are no updates in months.
EDIT: solution: https://github.com/apache/cordova-ios/issues/407
Someone has a solution? I tried changing "UNNotificationPresentationOptionAlert" to "UNNotificationPresentationOptionNone" in AppDelegate+FirebasePlugin.m ... without success :'(
I have a fix for this bug
NSNumber *background = self.applicationInBackground;
if([background boolValue]) {
completionHandler(UNNotificationPresentationOptionAlert);
} else {
completionHandler(UNNotificationPresentationOptionNone);
}
** edit **
This should replace
completionHandler(UNNotificationPresentationOptionAlert);
on line 183 of the AppDelegate+FirebasePlugin.m
@Farmertjes where did u add this code?
@kamilo81 in the AppDelegate+FirebasePlugin.m file at line 183 it seems to me
@Farmertjes when I apply your solution, notifications are always displayed when the app is active. In addition, when the app is not open (no process in background or foreground) notifications are not processed.
Could you give a little more detail on what you did to make it work?
I changed
PROJECT_ROOT/plugins/cordova-plugin-firebase/src/ios/AppDelegate+FirebasePlugin.m but also PROJECT_ROOT/platforms/ios/PROJECT_NAME/plugins/cordova-plugin-firebase/AppDelegate+FirebasePlugin.m.
In both files in line 183, I replaced
completionHandler(UNNotificationPresentationOptionAlert); with
completionHandler(UNNotificationPresentationOptionNone);
Now, it behaves like expected (no notification in foreground, only in background).
@cremfert there is no effect after these changes :'(
It works for me
@kamilo81 Do you have a special application configuration? This is the version 2.0.5 you use?
No. Its standard configuration. 2.0.5 it is
The notification is not intercepted by this plugins! There is a conflict with cordova-plugin-mauron85-background-geolocation 3.0.1 plugins...
Not sure, why this happens - I just installed the plugin and changed the mentioned files. After a new build, everything works for me. I'm using 2.0.5 as well. Push messages are received and shown when the app is in the background, but not when in foreground. In the latter case, only the callback in the is called with the data of the push message.
EDIT: Maybe it's due to the conflict - I'm not using any background mode plugins (like the one mentioned in your post @papattes)
I have a fix for this bug
NSNumber *background = self.applicationInBackground; if([background boolValue]) { completionHandler(UNNotificationPresentationOptionAlert); } else { completionHandler(UNNotificationPresentationOptionNone); }** edit **
This should replace
completionHandler(UNNotificationPresentationOptionAlert);on line 183 of the AppDelegate+FirebasePlugin.m
This solved the issue for me as well. Is there any reason the Firebase team has not addressed this yet? Could it be that rather than testing for background, is there a parameter we could be including in the payload instead? Or, could a solution involve changing configuration in XCode instead? It would be amazing to see if anyone from Firebase has feedback. Thanks in advance.