通过WhatsApp(React Native)直接将PDF共享给特定的人

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

我想通过WhatsApp直接与特定人共享PDF。还有其他方法吗?

我在下面尝试过,但并未直接分享给特定的人。

import Share from 'react-native-share';
Share.shareSingle(options);

我也尝试过此操作,但是它不能共享PDF,只能共享文本。

Linking.openURL(`whatsapp://send?text=${options}&phone=${options.phoneNumber}`);

更多代码:

  filePath = resp.path();
  (Platform.OS === 'android') ? filePath = 'file://' + filePath : filePath;
  let options = {
    type: 'application/pdf',
    url: filePath,
    title: "Share title",
    message: "Share message",
    subject: "Share subject",
    social: Share.Social.WHATSAPP,
    phoneNumber: "+60 12-345 6789"
  };
react-native pdf share whatsapp
1个回答
0
投票

安装react-native-fetch-blob

在RNFetchBlob配置中设置特定路径

    将PDF文件下载到临时设备存储中
  1. 直接共享已下载文件的响应的path()
  2. static sharePDFWithIOS(fileUrl, type) { let filePath = null; let file_url_length = fileUrl.length; const configOptions = { fileCache: true, path: DIRS.DocumentDir + (type === 'application/pdf' ? '/SomeFileName.pdf' : '/SomeFileName.png') // no difference when using jpeg / jpg / png / }; RNFetchBlob.config(configOptions) .fetch('GET', fileUrl) .then(async resp => { filePath = resp.path(); let options = { type: type, url: filePath // (Platform.OS === 'android' ? 'file://' + filePath) }; await Share.open(options); // remove the image or pdf from device's storage await RNFS.unlink(filePath); }); }
  • 以及适用于Android
  • static sharePDFWithAndroid(fileUrl, type) { let filePath = null; let file_url_length = fileUrl.length; const configOptions = { fileCache: true }; RNFetchBlob.config(configOptions) .fetch('GET', fileUrl) .then(resp => { filePath = resp.path(); return resp.readFile('base64'); }) .then(async base64Data => { base64Data = `data:${type};base64,` + base64Data; await Share.open({ url: base64Data }); // remove the image or pdf from device's storage await RNFS.unlink(filePath); }); }
  • © www.soinside.com 2019 - 2024. All rights reserved.