我正在尝试使用以下代码与 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]
})
不幸的是,文件没有与 iPhone 共享,但在 Android 上成功共享。
有什么解决办法吗?
提前致谢。
最佳答案
我得到了文件共享工作。但在 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;
});
https://jsfiddle.net/2q36fhb9/1/
关于javascript - 我可以在 Safari 上使用 Web Share API 共享文件吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60302475/