Ste*_*erg 4 javascript navigator whatsapp web-share
对于我正在构建的网络应用程序,我需要集成文件共享功能。自 iOS 15 发布以来,这终于成为可能。然而,我只让它部分工作。当我通过电子邮件或消息共享文件时,它工作正常。但当我尝试与 Whatsapp、Signal 或 Threema 共享时,它只会共享标题,而不共享实际文件。我在控制台中没有看到任何错误,也没有看到任何失败的网络请求。
const audioResponse = await fetch(sound.downloadUrl);
const fileBuffer = await audioResponse.arrayBuffer();
const fileArray = [
new File([fileBuffer], name + '.mp3', {
type: 'audio/mpeg',
lastModified: Date.now(),
}),
];
if (
window.navigator.canShare &&
window.navigator.canShare({ files: fileArray })
) {
navigator
.share({
files: fileArray,
title: name,
text: 'File share test',
})
.then(() => {
console.log('Success!');
})
.catch(console.error);
}
Run Code Online (Sandbox Code Playgroud)
我找到了解决方案。问题是标题属性,navigator.share这导致 IOS 上的某些应用程序认为我想共享文本而不是文件。
非常令人沮丧,因为这在其他浏览器中运行良好,但至少现在可以运行。
以下作品:
navigator
.share({
files: fileArray,
})
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1324 次 |
| 最近记录: |