【发布时间】:2020-09-25 06:04:15
【问题描述】:
附加的代码在 Android 上完美运行,即使是旧版本,也不能在 IOS 上运行(在 Safari 13 上测试)。 如果您尝试在 Whatsapp 上分享,在 android 上它也会分享照片,在 iphone 上只有文字。 我哪里错了? 代码笔: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>
【问题讨论】:
-
我不确定,但我认为这个示例使用了只有 chrome 75+ 支持的 web 共享 api 级别 2。
标签: ios share progressive-web-apps