我可以在 Safari 上使用 Web Share API 共享文件吗

Bog*_*zov 9 javascript safari mobile-safari navigator web

我正在尝试使用以下代码与 Web Share API Level 2 共享文件:

var file = new File(["foo"], "foo.txt", {
    type: "text/plain",
});

window.navigator.share({
    text: "Share text",
    title: "Share title",
    files: [file]
})
Run Code Online (Sandbox Code Playgroud)

不幸的是,文件未与 iPhone 共享,但在 Android 上成功共享。

有什么解决办法吗?

提前致谢。

Gab*_*ert 1

我的文件共享工作正常。但在 Whatsapp + iOS 上,它仅在文本和标题内容为空时才有效(仅发送文件)。

  let data = {};
  if (files.length > 0) {
    data.files = files;
  }
  if (title !== '')
    data.title = title;
  if (text !== '')
    data.text = text;
  if (url !== '')
    data.url = url;

  error.textContent = '';
  navigator.share(data)
    .then(() => {
  })
    .catch((err) => {
    console.log('Unsuccessful share');
    error.textContent = 'Share failed: ' + err.message;
  });
Run Code Online (Sandbox Code Playgroud)

https://jsfiddle.net/2q36fhb9/1/