我正在尝试通过网络共享像本机应用程序一样的图像。我也在使用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");
}
Run Code Online (Sandbox Code Playgroud)
我收到的错误是: Cannot use Web Share API
如果浏览器不受支持,通常会发生这种情况。但是,根据https://caniuse.com/#search=web%20share,iOS 上支持 Safari 13。请注意,我尝试将导航器对象记录到控制台,并且它确实具有 share() 原型。我在 HTTPS 服务器上运行它。请指导我如何进行。