FCM notification on-click always open in new tab (web-app Polymer) - firebase

I'm trying to implement Firebase Cloud Messaging in a web-app (with Polymer and a service-worker and using the custom-sw of the SDK).
It is working great (on both desktop and android) but when the user click on the notification it is always opening the click_action in a new tab even if a tab of the same origin is opened (but not focused).
click_action = "https://example.firebaseapp.com/demo/command"
Url of inactive tab = "https://example.firebaseapp.com/demo"
It seems that the getWindowClient_ method of the FCM SDK is not parsing correctly the URL of active clients and so can't call focus() on the inactive tab.
Any idea how to resolve this ?

That is how it is designed. It caught me off guard at first, but after I thought about it, the new tab/window made sense.
1) the service worker is a separate process from the browser.
2) when a notification displays it is not associated with a browser tab/window.
3) changing the url in an existing window would most likely confuse/irritate the user.
When the user clicks your button the notification assumes no active tab on the origin. So it opens a new window.

Related

how do i make wonderpush in app message to work for subscribing to web push?

I am having problem on wonderpush. I tried to use the in app functionality to have a custom message for user to subscribe to web push notification but it doesn't work.
I tried modifying the in app sample to use only 1 button to subscribe and it did not work. I see clicks but no one is subscribed to the push notification list. I have also disabled the native subscribe function.
Try removing the automatic subscription prompts like the HTML dialog and the Native Prompt in your Web Settings

Web app fetching background geolocation using service worker and push notification

I am looking for a solution to fetch geolocation periodically (every 1 minute) on mobile browser. I did some research and came to know that fetching geolocation in background (when phone is locked or webapp not active) is impossible. In foreground it works ok.
I am making a web app where I fetch user location and send it to my server. All works ok, until the point where user locks his/her phone. I tried many things for workarounds:
setInterval to get geolocation, works fine in foreground but fails in background
converted my web app into Android using cordova, but same problem existed
used https://github.com/mauron85/cordova-plugin-background-geolocation this plugin for android
works good in both foreground and background
but the same plugin does not work in iPhone (I did not tested it, I searched in Google before moving ahead)
Its not good to release my app with just one platform (android) support, thus this workaround also failed for me.
I also considered using serviceworkers for my web app but it seems issue persist for background
https://github.com/w3c/ServiceWorker/issues/745
I have another solution in mind, but before investing time in it, I wish to know if someone has tried it already.
I learnt about Push notifications:
Web app client registers to Push notification
It sends
subscriber object to my server
My server using this object sends
message to Push notification server
Push notification server
sends messages to my web app client
My web app client wakes up my
service worker for a brief period to show the notification message
As per google documentation:
Note: In the current implementation
of Chrome, whenever we receive a push message and we don't have our
site visible in the browser we must display a notification. That is,
we can't do it silently without the user knowing. If we don't
display a notification the browser automatically creates one to let
the user know that the app is doing work in the background.
I won't mind showing a permanent notification to users until my app is running. I am ready for this trade-off.
Now, my question is, at step 5, when I wake up the service worker **is there a chance I call my main.js (main web app) which might be running in background **, will fetch the geolocation and update it to my server?
Has someone tried this solution already with success or failure, please inform.
Can you try Page visibility Api, which listens for visibilitychange of a browser tab is hidden or switched to other tab (in case of browser). For mobiles, it's just a try.
src : https://developer.mozilla.org/en-US/docs/Web/API/Page_Visibility_API
or You can look into this answer too..
Detecting when screen is locked

UWP Windows syncing notifications with action center

Is there any way we can sync notifications with action center in Windows 10? Below is the scenario:
The Windows 10 UWP application I am building has the UI to see all the notifications user is receiving to the app. (I am using the background task to listen to raw notifications and saving to local xml file and show it in the app UI). Now, the requirement is there are many options to user to dismiss the notification. Means, From action center:
By clicking the x icon on individual notification.
By clicking on App title directly.
By clicking "clear" next to App Title.
By clicking "Clear All" on top of action center.
In either of the above cases, I need to delete the notifications from the App UI I am building as well. Can anyone help Windows 10 SDK has the support for listening to it when app is either in foreground running or not?
thanks in advance.
I suggest you to read Notifications History with
var history = ToastNotificationManager.History.GetHistory();
and compare with your app's data. If notifications are dismissed from action center, then you cannot find them in the history, so you could delete them also from your app.

iOS Push - display message if app is active

I'm implementing Push in a Xamarin Forms PCL project, and I'm having an issue with iOS.
If the user is actively using the app I want to display an alert to let them know they have received a notification and let them choose to View it (which changes the current page) or cancel.
If the app is not active, either in the background or not running, I want to go directly from the tap on the iOS notification to the notification page - no alert. I have this working if the app is not running.
If the app is running, either in the background or active, the RecievedRemoteNotifications function is called which will display the alert. I don't see a way in RecievedRemoteNotification to determine if the app was already active or if the user tapped the system-generated notification.
Check out the ApplicationState property from UIApplication.SharedApplication.
More information about the possible values here. There is a Background state.

How to display a notification in worklight when returning to the foreground?

I am using push notification in worklight 6.2 in one of my apps.
I have a issue regarding receiving of notification. i receive notification when i am in the application .
When i close my app or made my app go background, i receive notification in the status bar and when i click on that,its taking me to the app ask for the authentication which is provided in the app and then goes to the inbox where all the messages are listed the new message is displayed .
But when i receive the notification when my apps is in background and see the notification in status bar and without clicking that notification if i opened the application and see the inbox page ,the message is not displayed because the function which will be executed when receiving notification is not called.
I need to give solution to avoid this. Is there any way or option to display the notification which is received when the app is in background and when the app is opened without opening the notification in status bar.
Thanks in advance
Perhaps you could use a the Cordova resume event, from which you will call the pushNotificationReceived() function as the callback function.
document.addEventListener("resume", pushNotificationReceived, false);
The basic premise is that if a notification was received while you were in the background, then once returning to the foreground the above should executed and the notification will be displayed.
Again, this is just the basic premise and you'll probably need to modify the pushNotificationReceived() implementation to account for what happens when you get back to the foreground but there are no notification (you could implement some logic to check that...) and various other scenarios, as you encounter them.

Resources