我正在尝试通过网络共享类似于本机应用程序的图像。我同样使用Angular。我已经使用了网络共享API。这在Android上正常运行,但是在iOS(Safari和Chrome)上都会引发错误。我正在使用共享按钮触发此操作。
这是我的代码:
if (
this.windowNavigator.canShare &&
this.windowNavigator.canShare({ files: [file] })
) {
this.windowNavigator
.share({
files: [file],
title: "Vacation Pictures",
text: "Photos from September 27 to October 14.",
})
.then(() => console.log("Share was successful."))
.catch((error) => console.log("Sharing failed", error));
} else {
console.error("Cannot use Web Share API");
}
我收到的错误是: Cannot use Web Share API
如果不支持浏览器,通常应该发生这种情况。但是,根据https://caniuse.com/#search=web%20share,支持iOS上的Safari 13。请注意,我尝试将导航器对象记录到控制台,并且它确实具有share()原型。我正在HTTPS服务器上运行它。请指导我如何进行。
如您所知,您收到的错误消息是通过您自己的代码传播的。navigator
没有canShare
属性或navigator.canShare({ files: [file] })
返回错误时,将记录错误。
但是有问题的APInavigator.share
不是navigator.canShare
。对后者的支持更为有限。
根据截至2020年5月13日的MDN:
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句