So, we are implementing navigator.share()
(https://developers.google.com/web/updates/2016/09/navigator-share) in an Ionic v3 PWA.
It works, but there's a little problem we encountered which we don't know how to fix: when the navite share selector pops up (user can select betwen inbox, gmail, twitter, etc) and the user then presses the back button on android (dismissing the native modal that came up), the function doesn't trigger any response in the promise. Not success, not error.
The problem here is that we show a loading spinner before we call the navigator.share function and if the user presses that back button at that precise moment, we can't trigger the function that hides the loading spinner.
This is the part of the code where we implement the feature:
public share(title: string, message: string, url: string) {
// if it's mobile & web (ie: chrome on android)
if (this.isMobileWeb === true) {
this.showLoading();
if ((navigator as any).share) {
(navigator as any).share({
title,
message,
url,
})
.then(() => {
console.log('Success share');
this.hideLoading();
})
.catch((error) => {
console.log('Error share', error);
this.hideLoading();
});
}
else {
console.log('navigator.share() not supported.');
this.hideLoading();
}
}
}
With this implementation, no success or error is thrown if the user presses the back button when the native share modal comes up. Is there something wrong with this code?
I've also tried adding another callback function inside the .then()
function, as in: .then(successFn, errorFn)
. The errorFn
is never called either.
Thanks for your time.-