1

我在 Ionic 5 中使用社交共享插件,并且在通过 WhatsApp 共享图像时遇到问题。如果我通过“shareViewWhatsApp”共享图像,那么一切正常。选择联系人后,它会显示我正在共享的图像。

但是,如果我使用“shareViaWhatsAppToPhone”或“shareViaWhatsAppToReceiver”直接分享图片whatsapp联系人,那么它似乎会忽略图片而只分享短信。

var node = document.getElementById('body') ;
domtoimage.toPng(node) 
    .then((dataUrl) => {
      this.socialSharing.shareViaWhatsAppToPhone('+61xxxxxxxxx','share toPhone', dataUrl,null).then((res) => {
        console.log('image shared with whatsapp');
      }).catch((e) => {
        console.error('social share, something went wrong!', e);
      });
    })
    .catch((error) => {
        console.error('oops, something went wrong!', error);
    });

“domtoimage.toPng()”只是一个将Dom节点转换为图像的插件。参考:https ://github.com/tsayen/dom-to-image

dataUrl 看起来像:“data:image/png;base64,iVBORw0KGgoAAAANSUhEUg...”

任何帮助将不胜感激。

谢谢

4

1 回答 1

1

嗨,我早些时候遇到了同样的问题,后来我在这个文档中发现(https://www.npmjs.com/package/cordova-plugin-x-socialsharing)它清楚地提到文件在android中被忽略,同时直接发送到号码 在此处输入图像描述

所以你可以尝试类似的东西

this.socialSharing.shareViaWhatsApp('share toPhone', dataUrl,null).then((res) => {
      console.log('image shared with whatsapp');
    }).catch((e) => {
      console.error('social share, something went wrong!', e);
    });
  })
  .catch((error) => {
      console.error('oops, something went wrong!', error);
  });
于 2022-02-02T07:48:16.303 回答