The attached code works perfectly on Android, even old versions, and doesn't work on IOS (tested on Safari 13). If you try to share on Whatsapp, on android it also shares the photo, on iphone only text. Where am I wrong? Codepen: https://codepen.io/michitkt/pen/YzqBbxo
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimal-ui">
</head><body>
<button disabled="disabled">click me</button>
<div class="result"></div>
<script>
fetch('https://upload.wikimedia.org/wikipedia/commons/thumb/8/87/F-15C_53FS_36FW_Aviano_1993.jpeg/1920px-F-15C_53FS_36FW_Aviano_1993.jpeg')
.then(function(response) {
console.log("response",response);
response.blob().then(function(myBlob) {
console.log("blob",myBlob);
var file = new File([myBlob], "test.jpg", {type: 'image/jpeg'});
//alert("file: "+file.name+", size "+file.size);
productFilesArray = [file];
console.log("array file",productFilesArray);
btn.removeAttribute("disabled");
});
});
const btn = document.querySelector('button');
const result = document.querySelector('.result');
btn.addEventListener('click', async () => {
if (navigator.share) {
try {
await navigator.share({
title: 'Sharing',
text: 'Learn web development on MDN!',
url: 'https://developer.mozilla.org',
files: productFilesArray
})
result.textContent = 'Starting sharing';
} catch(err) {
result.textContent = 'Error: ' + err;
}
} else {
result.textContent = 'You can\'t share';
}
});
</script>
</body>
</html>