无法与WhatsApp或电子邮件共享PDF文件(仅IOS)

时间:2019-05-28 20:39:41

标签: ios react-native

我使用react-native-share包裹

https://www.npmjs.com/package/react-native-share

我尝试以这种方式共享base64:

import Share from 'react-native-share'
//
const base64File = //base64 file
const pdf = "data:application/pdf;base64," + base64File
const options = { title: 'Share via', url: pdf };
Share.open(options)

它在android中有效,但在IOS中无效,当我尝试共享tiff文件时,它在IOS中有效,但在pdf中无效

当我尝试此操作时会通知我-无法共享此文件

2 个答案:

答案 0 :(得分:0)

我在响应本机共享时遇到类似的问题。然后,我使用react-native-share共享我的pdf文件

Share.open({
            title: "Pdf file",
            message: "my Text:",
            url: "file:///storage/../../test.pdf",
            subject: "PDF",
        })

希望这对您有帮助

答案 1 :(得分:0)

解决方案

import Share from 'react-native-share'
import RNFetchBlob from 'rn-fetch-blob'
//
const base64File = //base64 file
const pdf = "data:application/pdf;base64," + base64File
let filePath = '';
const path = RNFetchBlob.fs.dirs.DocumentDir + '/someFileName.pdf';
const configOptions = { fileCache: true, path };
let fullPath = await RNFetchBlob.config(configOptions).fetch('GET', encodeURI(fileUrl))
filePath = fullPath.path();
let options = {
    title: 'Share via'
    type: type,
    url: filePath // (Platform.OS === 'android' ? 'file://' + filePath)
};
Share.open(options)