Closed sferoze closed 1 month ago
Hello @sferoze,
I register with my code below in one of my apps that is a PWA, but if in the future I'll start using Cordova to this app to publish in stores it will depend, because if I want the offline part of my app working inside Cordova I still need to have my service worker registered:
const iOS = () => {
const iDevices = [
'iPad Simulator',
'iPhone Simulator',
'iPod Simulator',
'iPad',
'iPhone',
'iPod',
];
return !!navigator.platform && iDevices.indexOf(navigator.platform) !== -1;
};
const register = () => {
if (!('serviceWorker' in navigator)) {
// eslint-disable-next-line no-console
console.log('serviceWorker is not in navigator!');
return;
}
if (iOS()) {
// eslint-disable-next-line no-console
console.log('iOS device then not register sw (was with error)!');
return;
}
navigator.serviceWorker
.register('/sw.js')
// eslint-disable-next-line no-console
.then(() => console.log('serviceWorker registered with success!'))
.catch(error => console.error('Error registering serviceWorker!', error));
};
register();
@filipenevola my app works offline in cordova and I do not register service worker.
Cordova apps, all the app code is already local to the device... works offline by default
Yeah yeah, I know, I'm talking about something offline provided by the service worker.
@filipenevola ah i see, thank you for sharing your code, it is very likely I will find it useful in the future
If your meteor app is compiled to all devices using Cordova, would it be a good idea to nest the call to register sw.js inside a !Meteor.isCordova so it does NOT run on Cordova?