问题
Is there a reliable way to create a file (specifically via Print.printToFileAsync API), and since it creates the new file in the user's cacheDirectory, copy it across to their documentDirectory - that works in both Android and iOS?
I've come across others trying to do the same thing here, but to no avail.
One solution I've seen is to use the MediaLibrary API to download the file to the device's CameraRoll - but this is hacky and doesn't work on iPhone since the file I'm trying to copy/download is a PDF, and not an image/movie.
Various solutions are listed here too - but they either don't work, or only work in one OS.
My end goal is to be able to generate a PDF on the device and save it to the user's storage, without needing to send information back to the server. My app is not ejected as it stands.
Any advice/direction would be appreciated!
EDIT 1:
Considering ejecting at some stage, but due to the nature of the project I'm working on I'd prefer to do that right at the end. Also came across this post which tries to Share the file URI, but this isn't supported on Android.
回答1:
I hope you dont have any problem with creating the pdf,to save the file have you tried
https://github.com/Lyrillind/react-native-file-manager
it supports both anroid and ios.
If you want you can build your own native module to save the file ,
http://facebook.github.io/react-native/docs/native-modules-ios.html#content
来源:https://stackoverflow.com/questions/55507959/expo-react-native-pdf-creation-download