PWA Webshare iOS 12.3

Hi Guys,

Trying to implement Webshare in PWA App, however it does not seem to work. iOS 12.2 implemented the feature.

I found this article.

Which also has a demo web page to test feature. Test page works on iPAD iOS 12.3
https://wicg.github.io/web-share/demos/share.html

The simple command is navigator.share({title, text, url}) nothing happens

Any ideas?

Ian.

Just tried it here and it worked fine:

JavaScript:

Button1.onclick = function() {
  args = {};
  args.title = "The Title";
  args.text = "The message";
  args.url = "https://example.com";
  navigator.share(args);
};

Basic:

Function Button1_onclick()
  args = {}
  args.title = "The Title"
  args.text = "The message"
  args.url = "https://example.com"
  navigator.share(args)
End Function

1 Like

Thank you, however running my app through the Web Inspector of MAC OS connecting my IPAD, I get this error.

[Error] Unhandled Promise Rejection: NotAllowedError: The request is not allowed by the user agent or the platform in the current context, possibly because the user denied permission.
(anonymous function)
rejectPromise
share

any ideas

Ian.

Do you get the same message running my app?

Yes it does.

I have found the error. You cannot run it within a function - outside the scope of an onclick event.

e.g.

function iosWebShare() {
 args = {};
  args.title = "The Title";
  args.text = "The message";
  args.url = "https://example.com";
  navigator.share(args);
};

call this function outside an click event say from another function.

You get the error.

Hope that makes sense.

Ian.

@ianResearch you’re saying that if you call the defined function iosWebShare() outside of an event handler, that you get a permission error?

Thats correct.

Seems odd.

When are you calling iosWebShare? Could it be before all the loading is done?

If you take a look at the demo you cited in your original message, the indirect call is done after a delay.

Calling in a menu option selection.

But I am going to do more testing, I can get it to work if i include a button and code in the button onclick all fine but if i call a function containing the code from the menu selection does not work.

I will get back to you once I have done some more checking.

Thank you

Ian.

Here’s another good document:

It notes:
To use the Web Share API:

  • you must be served over HTTPS
  • you can only invoke the API in response to a user action, such as a click (e.g., you can’t call navigator.share as part of the page load)