【问题标题】:how to use social sharing plugin in browser(pwa) in ionic 4?如何在 ionic 4 的浏览器(pwa)中使用社交分享插件?
【发布时间】:2023-03-10 20:15:01
【问题描述】:

如何在 ionic 4 的浏览器(pwa)中使用社交分享插件?
social sharing document 浏览器中支持平台。
但是在浏览器中使用时会抛出警告:

 Native: tried calling SocialSharing.share, but Cordova is not available. Make sure to include cordova.js or run in a device/simulator

【问题讨论】:

  • 我也面临同样的问题。你解决了吗?
  • 回复 Suraj Khanal,否
  • 你用电容试过了吗?还是cordova平台浏览器?

标签: ionic-framework progressive-web-apps


【解决方案1】:

如果您的目标是支持社交分享,现在可以访问手机的原生分享数据

            async function share(title, text, url) {
              if (window.Windows) {
                const DataTransferManager = window.Windows.ApplicationModel.DataTransfer.DataTransferManager;

                const dataTransferManager = DataTransferManager.getForCurrentView();
                dataTransferManager.addEventListener("datarequested", (ev) => {
                  const data = ev.request.data;

                  data.properties.title = title;
                  data.properties.url = url;
                  data.setText(text);
                });

                DataTransferManager.showShareUI();

                return true;
              } else if (navigator.share) {
                try {
                  await navigator.share({
                    title: title,
                    text: text,
                    url: url,
                  });

                  return true;
                } catch (err) {
                  console.error('There was an error trying to share this content');
                  return false;
                }
              }
            }  

您可以阅读更多Here

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-20
    • 1970-01-01
    • 2019-06-13
    • 1970-01-01
    相关资源
    最近更新 更多