有谁用过 navigator.share()这个 api?

2021-05-13 09:51:28 +08:00
 DeepUse

Navigator.share https://developer.mozilla.org/zh-CN/docs/Web/API/Navigator/share

if (navigator.canShare && navigator.canShare({ files: filesArray })) {
  navigator.share({
    files: filesArray,
    title: 'Pictures',
    text: 'Our Pictures.',
  })
  .then(() => console.log('Share was successful.'))
  .catch((error) => console.log('Sharing failed', error));
} else {
  console.log(`Your system doesn't support sharing files.`);
}

分享 files 的时候,不支持 iOS 和 Mac?有谁深入使用过这个 API,可以交流一下吗?

1536 次点击
所在节点    程序员
5 条回复
wheelg
2021-05-13 14:28:36 +08:00
iOS safari 实验特性里可以开启 web share api
no1xsyzy
2021-05-13 15:11:44 +08:00
没用过也没苹果设备,但瞄了眼
https://caniuse.com/mdn-api_navigator_canshare
safari 上支持 share 但不支持 canShare
看了下 w3c 的 spec 里面没有提到 canShare ; MDN 内指向 w3c 的链接失效,表示被移到前述的 w3c spec

也就是说 canShare 已经弃了。
DeepUse
2021-05-13 16:08:06 +08:00
@no1xsyzy 认真的人,谢谢啊!
ragnaroks
2021-05-13 23:35:17 +08:00
试了几个 chrome 的套壳浏览器,canShare() 总是返回 false,但 share() 是没问题的
DeepUse
2021-05-14 12:47:44 +08:00
@ragnaroks 谢谢你的经验

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/776637

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX