【问题标题】:Sharing files over webshare api only partially working on IOS 15通过 webshare api 共享文件仅在 IOS 15 上部分工作
【发布时间】:2021-09-22 17:37:30
【问题描述】:

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

【问题讨论】:

    标签: javascript whatsapp navigator web-share


    【解决方案1】:

    我找到了解决方案。问题是 navigator.share 中的 title 属性这导致 IOS 上的某些应用程序相信我想共享文本而不是文件。

    非常令人沮丧,因为这在其他浏览器中运行良好,但至少现在可以运行。

    以下作品:

    navigator
            .share({
                files: fileArray,
            })
    

    【讨论】:

    • 您是否也可以共享文本或文件?您说 title 属性是问题,但您的工作代码也省略了 text 属性。如果可能的话,我正在尝试找到一个解决方案来分享两者。
    • 我刚测试过,想要分享图片的不能分享任何文字...
    • 该死的,这需要修复......
    猜你喜欢
    • 2020-04-24
    • 1970-01-01
    • 2022-01-09
    • 1970-01-01
    • 2021-10-28
    • 1970-01-01
    • 1970-01-01
    • 2021-10-18
    • 1970-01-01
    相关资源
    最近更新 更多