I have some questions and I hope you can shed some light on all of those. Right now, I have a PWA written. No cordova or anything. Pure PWA with service worker, workbox and offline support.
Requirements:
a) I need to have a PWA website so that users can see my website via url.
b) I need my app to be on play store and app store.
c) I need the website and my apps to support push notifications.
Question 1) As you know, It’s possible to publish PWA on google play store and somehow app store(not sure yet). But if I do that, I won’t be able to have push notifications for IOS. so the only way if I want to provide push notifications for ios too is to use cordova
or capacitor
. Am I right?
Quesiton 2) If I use capacitor
, then publishing PWA to playstore and appstore isn’t worth it because by using capacitor
i already can publish them as almost native
apps. Is that right? is this how you would do it?
Question 3) I tried to use capacitor
for the first time today and here is the code I’ve written for push notifications.
import {
Plugins
} from '@capacitor/core'
const { PushNotifications } = Plugins;
PushNotifications.register();
PushNotifications.addListener('registration', function(e){
console.log("eee ", e);
})
PushNotifications.addListener('registrationError', function(e){
console.log("err ", e);
});
the thing is, when building this through xcode
after I use npx add ios
and npx cap copy
, I can see that push
notifications work on ios now. The bad thing is that now, If I run this via my website url, let’s say chrome, it says that Uncaught (in promise) PushNotifications does not have web implementation.
. So Now, I’m really stuck. Does this mean that I have use if else
statements to first check what target user uses
and if it’s web
, I should use browser's PushAPI
? and if the target is ios or android
, I’d use the above code. Because of the fact that I use service worker
because my app is PWA, I can simply put push
listener in service worker and now, I’d make push notifications for all platforms. Is this if else
and checking platform and using PushAPI
or capacitor's push notifications
a great practice? or what other idea can you provide?
Question 4) It turns out that if I use capacitor
i have to include @capacitor/core
which will make the bundle size bigger for web. Now, the thing is if user goes to web version, My website size will be bigger, but the thing is size is bigger, but i don’t use capacitor's plugin
at all. Is this unavoidable?
I’d really appreciate your sincere answers since there’s not many people who can help.