Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

168
Visualizações
Web Share API Not Working On Some IOS Versions

I am using the Web Share API to allow downloading/sharing an image from my web app. I have followed the documentation and have it working well, however, on certain IOS devices the share API fails. I've noticed this happen on IOS 12, 14, and even 15. It works fine on my personal iPhone running 15.1.1 but it fails on our client's iPhone running some version of IOS 15 (not sure the exact version). I have not seen this issue with any android devices so far.

// This function is called when the use hits the take screenshot button on the app. This is where we are creating the image that will be shared via Web Share API

function createFinalImage() {
    const screenshotContainer =  document.getElementById("screenshot-container") 

    // here we are turning all elements in our screenshot container into one image
    html2canvas(screenshotContainer).then(canvas => {

        try {
            var finalScreenshot = canvas.toDataURL('image/jpeg', 1);

            // share image
            shareScreenshot(finalScreenshot)
        }
        catch (e) {
            console.log("Screenshot failed: " + e);
        }

    });
}

// Here we are sending the image to the web share API

async function shareScreenshot(finalScreenshot) {
    const blob = await (await fetch(finalScreenshot)).blob();

    const filesArray = [
      new File(
        [blob],
        `harry-caray${Date.now()}.jpg`,
        {
          type: blob.type,
          lastModified: new Date().getTime()
        }
      )
    ];

    const shareData = {
      files: filesArray,
    };

    if (navigator.canShare && navigator.canShare({ files: filesArray })) {
        navigator.share(shareData);
    } else {
        console.log(`Your system doesn't support sharing files.`);
    }
}

// share screenshot 
document.getElementById("share-button").addEventListener("click", function() {
    createFinalImage()
});

On the devices that Web Share fails on, I am seeing "Your system doesn't support sharing files." in the console so that's where it is erroring out.

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

General hint: wrap the await navigator.share() call in try..catch. Like that you can know if someone just cancels the share operation (throws AbortError) or if it actually fails (throws other error).

The Web Share API with the files parameter is supported by browsers as you can see on CanIUse. People might have toggled a feature flag in Safari to enable support before the API was actually supported.

about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda