I am trying to let users share a PDF, so I can't just specify the encoding as a workaround or share will share it as a textfile. Here's the code:
function shareFile(fileName, base64Data) {
return Filesystem.writeFile({
path: fileName,
data: base64Data,
directory: Directory.Cache,
// encoding: Encoding.UTF8 <-- this line fixes writeFile but
// breaks share
recursive: true
})
.then(() => {
return Filesystem.getUri({
directory: Directory.Cache,
path: fileName
});
})
.then((uriResult) => {
return Share.share({
title: fileName,
text: fileName,
url: uriResult.uri,
dialogTitle: fileName
});
});
I've tested with multiple PDF files. They all work on android but fail on all versions of ios I have tried. If I let it encode as UTF8, the shared file is just a shared utf8 encoded base64 string instead of a PDF.