How to access files in IOS that are stored in Files.app using react-native-fs?

2.5k views Asked by At

I'm looking for a way to access the Files.app directory mainly the "Downloads" directory but the directory marked as "On My iPhone" would work as well. The use case will be a user downloads a certificate outside of the app into Files.app and the app will browse the directory for that certificate. I am using 'react-native-fs' and have tried using several file directory paths provided by the library such as DocumentDirectoryPath and LibraryDirectoryPath. I have also added UISupportsDocumentBrowser to the info.plist all with no luck.

Just for testing I am using:

    RNFS.readDir(RNFS.DocumentDirectoryPath).then(files => {
        console.log(files);
    })
    .catch(err => {
        console.log(err.message, err.code);
    });
2

There are 2 answers

2
matt On BEST ANSWER

The file manager cannot magically "see" into the Files app world. That world belongs to the Files app! You are sandboxed. You can allow the user to choose a file from the Files app using the documents browser, but you can't just magically peer into it.

0
NathanNovak On

If you are trying to access the Files.app you can open it through your app by adding LSApplicationQueriesSchemes as an Array in info.plist. Then add shareddocuments (without the ://). This allows Files to be opened on a button press if you want.

If you are trying to access a document in the filesystem on iOS then react-native-document-picker is a good one to use. I have done that to grab .CSV files stored anywhere on On My Ipad or Cloud.