对于我正在构建的网络应用程序,我需要集成文件共享功能。自 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)