简体   繁体   English

离子电容器共享插件不与whatsapp共享图像

[英]ionic capacitor share plugin not sharing image with whatsapp

I have created this function that shares image very well on many applications, but when it comes to WhatsApp or Instagram it not sharing the image.我已经创建了这个功能,可以在许多应用程序上很好地共享图像,但是当涉及到WhatsApp或 Instagram 时,它不会共享图像。

I'm using Ionic v5 with capacitor v3我正在使用带有电容器 v3 的 Ionic v5


  async shareImage() {
    let receiptName = 'Receipt N:123.png';
    const div = this.screenshotElement.nativeElement;
    const divHeight = div.clientHeight;
    const divWidth = div.clientWidth;
    const options = { background: '#ffffff', width: divWidth, height: divHeight };

    await Filesystem.requestPermissions();

    let base64Data = await domtoimage.toPng(div, options);

    // device shareing
    await Filesystem.writeFile({
      path: receiptName,
      data: base64Data,
      directory: Directory.Cache
    });


    let fileResult = await Filesystem.getUri({
      directory: Directory.Cache,
      path: receiptName
    });

    let imageLink = Capacitor.convertFileSrc(fileResult.uri);

    Share.share({
      title: receiptName,
      text: receiptName,
      url: fileResult.uri,
    })
      .then(() => console.log('Successful share'))
      .catch((error) => console.log('Error sharing ::: ', error));

  }


import进口

import domtoimage from 'dom-to-image';
import { Share } from '@capacitor/share';
import { Filesystem, Directory, Encoding } from '@capacitor/filesystem';
import { Capacitor } from '@capacitor/core';
import { Camera, CameraResultType } from '@capacitor/camera';

package包裹

 "@capacitor/android": "^3.1.1",
        "@capacitor/app": "^1.0.2",
        "@capacitor/camera": "^1.0.3",
        "@capacitor/cli": "^3.1.1",
        "@capacitor/core": "^3.1.1",
        "@capacitor/filesystem": "^1.0.2",
        "@capacitor/haptics": "^1.0.2",
        "@capacitor/ios": "^3.1.1",
        "@capacitor/keyboard": "^1.0.2",
        "@capacitor/push-notifications": "^1.0.3",
        "@capacitor/share": "^1.0.3",
        "@capacitor/status-bar": "^1.0.2",

I found that @capacitor/share has this known issue.我发现@capacitor/share 有这个已知问题。

see: https://github.com/ionic-team/capacitor-plugins/issues/196见: https ://github.com/ionic-team/capacitor-plugins/issues/196

I solved it by using我通过使用解决了它

npm install cordova-plugin-x-socialsharing
npm install @ionic-native/social-sharing
ionic cap sync

see: https://ionicframework.com/docs/native/social-sharing见: https ://ionicframework.com/docs/native/social-sharing

也可以使用Capacitor Filesharer为我节省了很多压力!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM