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

ldxq2e6h  于 2022-12-09  发布在  Ionic
关注(0)|答案(2)|浏览(165)

我已经创建了这个功能,在许多应用程序上很好地共享图像,但当涉及到WhatsApp或Instagram时,它不会共享图像。

我正在使用Ionic v5和电容器v3

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 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",
r1zk6ea1

r1zk6ea11#

我发现@capacitor/share存在此已知问题。
请参阅:https://github.com/ionic-team/capacitor-plugins/issues/196
我用了

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

请参阅:https://ionicframework.com/docs/native/social-sharing

txu3uszq

txu3uszq2#

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

相关问题