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?

Thaina Yu
  • 1,372
  • 2
  • 16
  • 27
  • 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 further – a.masri Apr 12 '18 at 06:49
  • @a.masri Can those run in "serviceworker" ? – Thaina Yu Apr 12 '18 at 06:52
  • 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 question – a.masri Apr 12 '18 at 07:03
  • @a.masri Do you know what is "serviceworker" ? – Thaina Yu Apr 12 '18 at 10:33
  • If you mean service worker js yes I know him – a.masri Apr 12 '18 at 11:40

3 Answers3

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.

Anand
  • 9,672
  • 4
  • 55
  • 75
  • 1
    `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 noti – Thaina Yu Apr 14 '18 at 08:19
  • 1
    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. – Anand Apr 14 '18 at 09:28
  • 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. – Anand Apr 14 '18 at 09:31
  • 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. – Anand Apr 14 '18 at 09:34
  • I think there was a function `showLocalNotification` isn't it? – Thaina Yu Apr 14 '18 at 12:46
  • 1
    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. – Anand Apr 14 '18 at 23:46
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/.

Riley Davidson
  • 307
  • 3
  • 7
-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.!

Aditya Naik
  • 27
  • 1
  • 6
  • 1
    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 directly – Thaina Yu Apr 12 '18 at 15:50
  • @Thaina did you try it? If yes, can you share it? (github maybe?) – jvitor83 Oct 23 '18 at 22:21
  • @jvitor83 I don't have my own ios device so I cannot try it – Thaina Yu Oct 24 '18 at 01:01