【发布时间】:2020-05-13 12:17:49
【问题描述】:
我正在尝试通过网络共享像本机应用程序一样的图像。我也在使用 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 服务器上运行它。 请指导我如何进行。
【问题讨论】:
标签: javascript angular typescript web-share