Estoy usando la API Web Share para permitir descargar/compartir una imagen desde mi aplicación web. He seguido la documentación y funciona bien, sin embargo, en ciertos dispositivos IOS falla la API compartida. He notado que esto sucede en IOS 12, 14 e incluso 15. Funciona bien en mi iPhone personal que ejecuta 15.1.1 pero falla en el iPhone de nuestro cliente que ejecuta alguna versión de IOS 15 (no estoy seguro de la versión exacta). No he visto este problema con ningún dispositivo Android hasta ahora.
// 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() });En los dispositivos en los que falla Web Share, veo "Su sistema no admite el uso compartido de archivos". en la consola, así que ahí es donde está fallando.
Sugerencia general: ajuste la llamada await await navigator.share() en try..catch . De esa manera, puede saber si alguien simplemente cancela la operación de compartir (arroja AbortError ) o si realmente falla (arroja otro error).
La API Web Share con el parámetro de files es compatible con los navegadores, como puede ver en CanIUse . Es posible que las personas hayan activado un indicador de función en Safari para habilitar el soporte antes de que la API fuera realmente compatible.