Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide iOS push notifications when app is in foreground #835

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Hide iOS push notifications when app is in foreground #835

wants to merge 1 commit into from

Conversation

ghost
Copy link

@ghost ghost commented Sep 8, 2018

This hides the push notification in iOS if the app is in foreground by using UNNotificationPresentationOptionNone instead of UNNotificationPresentationOptionAlert in the completion handler.

@rwoody
Copy link

rwoody commented Sep 8, 2018

Is is possible to have this determined by a configuration option? I'd like to receive notifications in the foreground, especially because cordova-plugin-local-notifications conflicts with this plugin.

@soumak77
Copy link
Contributor

soumak77 commented Sep 8, 2018

Yes we should keep the default functionality as is and the configuration option should allow hiding the notification when the app is in the foreground.

@maitscha could you update the PR and add a new IOS_HIDE_FOREGROUND_NOTIFICATION variable which defaults to false?

I'm up to suggestions on better naming for the variable if people have strong opinions on the naming

@ghost
Copy link
Author

ghost commented Sep 11, 2018

Should we use a Swift compiler flag, or what do you mean with "variable"?

For example:

#if IOS_HIDE_FOREGROUND_NOTIFICATION
    completionHandler(UNNotificationPresentationOptionNone);
#else
    completionHandler(UNNotificationPresentationOptionAlert);
#endif

@soumak77
Copy link
Contributor

soumak77 commented Sep 11, 2018

We need a cordova variable so that users can install the plugin using the command:

cordova plugin add cordova-plugin-firebase --variable IOS_HIDE_FOREGROUND_NOTIFICATION ="false"

@ghost
Copy link
Author

ghost commented Sep 12, 2018

Unfortunately I never used a --variable command :-( Is this an official feature of Cordova plugins?

@soumak77
Copy link
Contributor

soumak77 commented Sep 12, 2018

Yes, usage of variables to configure Cordova plugins is standard. See the docs here: https://cordova.apache.org/docs/en/latest/config_ref/#variable

@soumak77
Copy link
Contributor

@maitscha here's some more info on adding variables to plugins: https://gist.github.com/mlynch/c9a469948680979a8740d68c47d1cf98#adding-variables

@ColDrekken
Copy link

This hides the push notification in iOS if the app is in foreground by using UNNotificationPresentationOptionNone instead of UNNotificationPresentationOptionAlert in the completion handler.

hello, i tried to change this manually in v2.0.1 and made a build with it but it seems not change the behavior.

the strange thing i found is that i have another app no2 with same code base where i did not made the change but its working as expected there with "UNNotificationPresentationOptionAlert" with version 2.0.1 . The incoming pushes are recognised with app in foreground but did not show as it should.

Any ideas?

best regards

@kirill-kostenetskyi
Copy link

Does this works in the new version of the plugin? This is the really huge issue for me

@briantq
Copy link
Contributor

briantq commented Sep 21, 2018

@neustart it is not in the newest version of the plugin as it has outstanding modifications. If you would like to make those modifications to get the feature added quicker, please see the Contribution Guidelines. Making the changes yourself is always the fastest way to get something resolved :)

@ColDrekken
Copy link

hi @maitscha, do you have any other idea why this has no effect on my side?

I double checked my 2 Apps now about what is used in xcode project at least on file AppDelegate+FirebasePlugin.m but on app 1 and app 2 the setting you suggest in line 168 is "completionHandler(UNNotificationPresentationOptionAlert);"

in app 1 it works as expected, in app 2 not.
both are using the 2.0.1 version of the plugin.

Im not that familiar with the native iOS code but it seems to be related to something else from a logical point of view.

best regards

@ghost
Copy link
Author

ghost commented Sep 24, 2018

hi @maitscha, do you have any other idea why this has no effect on my side?

I double checked my 2 Apps now about what is used in xcode project at least on file AppDelegate+FirebasePlugin.m but on app 1 and app 2 the setting you suggest in line 168 is "completionHandler(UNNotificationPresentationOptionAlert);"

If you want to hide the notifications for a running in-foreground app, you have to use the option UNNotificationPresentationOptionNone.

@ColDrekken
Copy link

ColDrekken commented Sep 24, 2018

If you want to hide the notifications for a running in-foreground app, you have to use the option UNNotificationPresentationOptionNone.

@maitscha i understood and tried this. But it wont work on my side.

Also, it does not explain why it hides as expected in one app with UNNotificationPresentationOptionAlert, but not in the other one.

bildschirmfoto 2018-09-24 um 10 08 41

@laychar
Copy link

laychar commented Sep 24, 2018

@maitscha I have the same issue. which file I should modify?

@briantq
Copy link
Contributor

briantq commented Sep 24, 2018

@laychar Is that question related to the pull request? If so, I believe you need to modify the install scripts as that is the outstand issue with the current PR in its current state. If you are talking about working around the issue, please use the issue #817 to have that conversation as the PR should be related only to proposed code changes.

@laychar
Copy link

laychar commented Sep 25, 2018

Thank you for your answer. But I want to change UNNotificationPresentationOptionAlert to UNNotificationPresentationOptionNone.
But I don't know which file contains UNNotificationPresentationOptionAlert.

@laychar
Copy link

laychar commented Sep 26, 2018

@ColDrekken Did you solve this problem? I modify UNNotificationPresentationOptionAlert to UNNotificationPresentationOptionNone like you did. But It did not work as your app.

@ColDrekken
Copy link

@laychar unfortunately no...

but my feeling is that this is not really related to UNNotificationPresentationOptionAlert Option. As i said i have 2 Apps which are just have another branding. Both uses V2.0.1 of the plugin and both have "UNNotificationPresentationOptionAlert " in AppDelegate+FirebasePlugin.m but it only works in one app as expected. And i did not found the difference yet.

@maitscha @briantq im not that familiar with Swift or Objective C. Could there be another part that cause that behavior? What could be the reason that it works in one app but not in the other with same code?

@briantq
Copy link
Contributor

briantq commented Sep 27, 2018

@ColDrekken I don't know the code intimately, but you can check out FirebasePlugin.m and AppDelegate+FirebasePlugin.m as those two files contain most of the business logic. You should be able to put breakpoints in via XCode and trace what is happening. Sorry I can't be more help

@laychar
Copy link

laychar commented Sep 28, 2018 via email

@wildhart
Copy link

I have also tried manually changing that line to UNNotificationPresentationOptionNone then built and installed the app, and the notifications still popup even when the app is open.

@laychar
Copy link

laychar commented Oct 12, 2018 via email

@yomencity
Copy link

#817

@jfougere
Copy link
Contributor

jfougere commented Nov 9, 2018

Hi guys,

I am facing same issue on iOS 12 device and doing the change proposed in this PR is fixing it for me.
(I am on version 2.0.5 of this plugin)

@ColDrekken
Copy link

Hi @ALL. Meanwhile i personally think this issue is not related to UNNotificationPresentationOptionNone Or Alert. Because I got three apps which have nearly the same code base and using 2.0.5 and only two of them have the problem. One is working as expected but I could not figure out yet what was the difference...

@jfougere
Copy link
Contributor

jfougere commented Nov 9, 2018

@ColDrekken are you testing your different apps on a single device ? single iOS version ?

For me, with a device on iOS 12, switching from UNNotificationPresentationOptionAlert to UNNotificationPresentationOptionNone on the completionHandler makes all the difference and clearly fix the issue. I can't say however if it's true for other iOS version.

@ssijak
Copy link

ssijak commented Nov 17, 2018

When will this get merged?

@skined90
Copy link

Any news on this one?

@ssijak
Copy link

ssijak commented Nov 22, 2018

Any news on this one?

Haha, de si Igore. Sasa iz Altee ovde. Ja koristim ovaj fork https://github.com/jfougere/cordova-plugin-firebase koji ima ovo sredjeno.

@sebastianludwig
Copy link

@soumak77 #913 implements your suggestion to use a variable. Please review and merge (and close this one).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.