[英]Send Image using Social Sharing Plugin in ionic
I am generating QR, and i want to share that generated QR (via) Social Sharing Plugin.我正在生成二维码,我想分享生成的二维码(通过)社交分享插件。 Below is my code to share the image.下面是我分享图像的代码。
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 is the string for generating QR. this.createdCode 是生成二维码的字符串。 The problem is, this plugin shows action sheet with list of sharing applications.问题是,这个插件显示了带有共享应用程序列表的操作表。 But i can't able to transfer image with list of sharing apps.但我无法使用共享应用程序列表传输图像。 But i can able to transfer text.但我可以传输文本。 Can anyone please let me know how to transfer image with social sharing plugin.任何人都可以让我知道如何使用社交共享插件传输图像。
Social sharing plugin accepts the image as a string, so if you're using qrcode package, you can share the qr code generated to social media using data url like this:社交分享插件接受图像作为字符串,因此如果您使用的是 qrcode 包,您可以使用数据 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();
})
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.