【问题标题】:Send Image using Social Sharing Plugin in ionic使用 ionic 中的社交共享插件发送图像
【发布时间】:2019-04-25 22:14:10
【问题描述】:

我正在生成 QR,我想分享生成的 QR(通过)社交分享插件。下面是我分享图像的代码。

share() {

let currentImage= "data:image/jpeg;base64,"+ this.createdCode;
this.socialSharing.share("QR Image to share", "QRCode", currentImage, '').then(()=>{ 
  console.log('sharing success'); 
  }).
catch(()=>{ 
  console.log('not possible to share '); 
});
}

this.createdCode 是生成二维码的字符串。问题是,这个插件显示了带有共享应用程序列表的操作表。但我无法使用共享应用程序列表传输图像。但我可以传输文本。谁能告诉我如何使用社交共享插件传输图像。

【问题讨论】:

  • 您可以尝试使用 html2canvas 隐藏包含 qrcode 的 div 并尝试共享生成的图像。查看这个有用的链接 - jsfiddle.net/8ypxW/3
  • 你找到实现这个的方法了吗?
  • 是的,我使用了 HTMLTOCANVAS 插件。我通过社交分享插件转换和转移。
  • @user7413163 你能说明你是如何解决这个问题的吗?

标签: angular ionic-framework hybrid-mobile-app socialshare


【解决方案1】:

社交分享插件接受图片作为字符串,所以如果你使用二维码包,你可以使用这样的数据url将生成的二维码分享到社交媒体:

const options = {
  errorCorrectionLevel: 'H',
  type: 'image/jpeg',
  quality: 0.3,
  margin: 4
}

qrCode.toDataURL('sample text', options, (err, url) => {
  if (err) throw err   
  this.socialSharing.shareViaTwitter("Share via Twitter", url)
   .then(async () => {
      const alert = await this.alert.create({
        header: 'Alert',
        subHeader: 'success',
        message: 'shared successfully',
        buttons: ['OK']
      });
      await alert.present();
   }).catch(async (err) => {
      const alert = await this.alert.create({
        header: 'Alert',
        subHeader: 'error',
        message: 'Error, Did not share because: ' + err,
        buttons: ['OK']
      });
    await alert.present();
  })
})

【讨论】:

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