簡體   English   中英

離子電容器共享插件不與whatsapp共享圖像

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

我已經創建了這個功能,可以在許多應用程序上很好地共享圖像,但是當涉及到WhatsApp或 Instagram 時,它不會共享圖像。

我正在使用帶有電容器 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 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';

包裹

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

我發現@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

也可以使用Capacitor Filesharer為我節省了很多壓力!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM