Can we run firebase realtime listening on ios serviceworker?
Asked Answered
Z

3

9

As of iOS 11.3 there is serviceworker feature supported

Even though it has no support for notification. I wonder if it possible to just run any realtime listener, such as firebase database, to receive realtime data and use ServiceWorkerRegistration.showNotification to show local notification instead

Is it possible?

Zooplankton answered 10/4, 2018 at 4:15 Comment(5)
if you need get data real time from firebase you can use observe(DataEventType.value,....) or you can use web socket IO listener on Please explain the question furtherStarspangled
@Starspangled Can those run in "serviceworker" ?Zooplankton
So far I have not understood your question but if you want to show local notification on listener websocket, You can do this but this solution do not working if you're app killed ,I hope I understand your questionStarspangled
@Starspangled Do you know what is "serviceworker" ?Zooplankton
If you mean service worker js yes I know himStarspangled
Y
15

While iOS don't support Web Push notifications yet(as of Apr-2018), all you can do is have an event listener for data from server side(Firebase in your case) and receive that data to show it as an Notification/alert or how ever you want to present inside your application(not in iOS notification area).

Unfortunately, this is the best way you can handle notifications for iOS. I know, its not so great for developers :) Hope Apple speeds up on PWA. They are more than a year late to Service worker party itself. What to expect!

Update : One more link on WhatWebCanDo.today and one from Apple which says iOS-Safari don’t support push notification as a web standard defined by w3c. But looks like there is a OS X safari proprietary solution available.

Yare answered 12/4, 2018 at 18:15 Comment(6)
have an event listener for data from server side and receive that data to show it as an Notification This is what I would like to do but in the serviceworker that's the point. So even the page was closed the service worker still running in background and can show noti like a real push notiZooplankton
The real problem is you don’t have a way to send notification. It’s not about the option of listening on the server change or anything. Were you able to push notification when the app is actively used ? Guess no.. reason being safari or iOS still doesn’t support it. So until they support it, only other way is to have a native wrapper.. like Cordova to wrap your PWA and use native push notification. Ya .. not pure PWA solution.. but that’s all you got now for iOS if that’s a must have feature. You still get service workers. But you have to go though App Store deployment option.Yare
And if you are thinking of having service worker listening for data and to show notification in app(not system) notification, that’s not possible either as iOS puts the app with no state preserves and won’t lets you open the app without user requesting explicitly. So in both the case, issue is not even about how to listen for data. It’s about how you show the notification and pure PWA don’t have a solution for iOS as of Apr-2018. I know this is not what u like to hear. But unfortunately this is all we got for now.Yare
Also on the 2nd option, opening iOS app to show in app notification is not a great user experience when he is actively working with some other app. Apple wouldn’t allow that for the same reason.Yare
I think there was a function showLocalNotification isn't it?Zooplankton
Please check my update on safaris propitiatory solution. W3C defines what web standards are wth specific API syntax. That doesn’t guarantee all browsers support as soon as they are defined. Many browser vendors take lots of time compared to others (like chrome which is generally fast). Push notification is one such. Apple is still not supporting the W3C standard API. Whatwebcando.today is one good place to validate that for yourself.Yare
D
1

Unfortunately not, while Safari on native IOS is getting closer to the functionality we see in chrome, firefox etc. we currently ( as of this comment ) do not have anyway of sending push notifications on native IOS Safari ( or any other ios browser like chrome etc. ).

Safari for mac uses a custom mac solution for these notifications which you can check out here https://developer.apple.com/notifications/safari-push-notifications/.

Delaine answered 18/9, 2019 at 1:54 Comment(0)
S
-3

If you're using firebase then you will find push notification in main terminal of your firebase project and you won't be able to run service worker javaScript on it for offline data handling but you can use it for push notification. can you explain more about question be brief.!

Seaward answered 12/4, 2018 at 15:42 Comment(3)
First point : Safari iOS don't support web push, that's include FCM and any other service nowaday. Second point : Safari iOS do support serviceworker recently, which mean we can still run some script in background thread outside of the page. These points lead me to wonder that can we run firebase db listener in serviceworker. So we can launch notification even safari iOS don't support it directlyZooplankton
@Thaina did you try it? If yes, can you share it? (github maybe?)Marbut
@Marbut I don't have my own ios device so I cannot try itZooplankton

© 2022 - 2024 — McMap. All rights reserved.