Ionic SocialSharing 与 Whatsapp 的 pdf 文件

问题描述 投票:0回答:1

我正在使用 pdfMaker 创建一个 Document 类型的对象,我想将此文件发送给我在 Whatsapp 上保存的联系人,这类似于使用

shareViaWhatsAppToReceiver
使用
SocialSharing
函数。

文件的附件已包含在消息中。

   this.socialSharing.shareViaWhatsAppToReceiver(`+55 ${contact.phone}`, `PDF`,
      null, this.pdfObj).then(async () => {
        const toast = await this._toast.create({
          message: 'Send success.',
          duration: 3000
        });
      });

我上面的方法不行,我想直接将文档作为参数发送,以便附加Whatsapp上的消息。

ionic-framework cordova-plugins
1个回答
0
投票
const serverPdfUrl = filePath; //'https://example.com/path-to-your-pdf.pdf';  // URL of the PDF file on your server
const fileName = 'my_file_pdf.pdf'; // Name to save the file as on the device
const localPath = this.file.externalDataDirectory + fileName; // Path to save the file on the device

// Create a file transfer object
const transfer: FileTransferObject = this.fileTransfer.create();

// Download the PDF file
transfer.download(serverPdfUrl, localPath).then(
  (entry) => {
    alert('File downloaded successfully:'+ JSON.stringify(entry) );

    // After downloading, share the PDF file via WhatsApp
    this.socialSharing.share('title', 'message', localPath, 'whatsapp')
      .then(() => {
        alert('PDF file shared successfully!');
      })
      .catch((error) => {
        alert('Error sharing PDF file:'+ JSON.stringify(error) );
      });
  },
  (error) => {
    alert('Error downloading PDF file:'+ JSON.stringify(error));
  }
);
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.