react-native-fs icon indicating copy to clipboard operation
react-native-fs copied to clipboard

Missing instructions on how to make appear files into "File" app on iOS (with fix)

Open Martinocom opened this issue 2 years ago • 6 comments

The thing is pretty straightforward. The guides on how to use RNFS do not explain carefully that iOS hides by default the files that you save. Every app in iOS has its "sandbox" when they can write/read without any major restrictions, but by default users aren't able to see any files. This could be potentially a problem if saved files are needed for the final user.

On Android this problem does not exist, since you can write, for example, in Download folder, if storage access is granted.

This was very unclear for me: the functions as write or exists was working: they both was returning ok when finishing saving or checking if file exists, but I couldn't see the files in the File app. Since I have some apps installed on my device, I saw that everyone has his folder inside on My iPhone but mine didn't.

After 2 days spending on understanding what permissions do I need or what I'm doing wrong, I discovered that you need to explicitly indicate to iOS that your app is able to "expose" internal files, in order to make it visible inside File app. Solution is very easy: just add this lines into your info.plist file (located in ios folder in your react-native project):

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    ....
    <key>UIFileSharingEnabled</key>
    <true/>
    <key>LSSupportsOpeningDocumentsInPlace</key>
    <true/>
    <key>UISupportsDocumentBrowser</key>
    <true/>
</dict>
</plist>

This will indicate that your app is exposing file saved inside RNFS.DocumentDirectoryPath and user can access them with the File app.

It would be great to add this instruction to README.

Martinocom avatar Sep 08 '22 15:09 Martinocom

I have one question. Do the files persist after performing an app update on iOS? I am currently using another library and after implementaion, I found out that the absolute paths to the files change whenever an update is performed through Testflight. Any ideas how to persist the paths to local files after updates? Thanks.

Vick-Bay avatar Sep 22 '22 03:09 Vick-Bay

Actually I don't know. I saw that our iPhones updates some days ago and I can check if our test files are still there. But I don't know about this, since I'm not a proper iOS dev :)

Martinocom avatar Sep 23 '22 18:09 Martinocom

The thing is pretty straightforward. The guides on how to use RNFS do not explain carefully that iOS hides by default the files that you save. Every app in iOS has its "sandbox" when they can write/read without any major restrictions, but by default users aren't able to see any files. This could be potentially a problem if saved files are needed for the final user.

On Android this problem does not exist, since you can write, for example, in Download folder, if storage access is granted.

This was very unclear for me: the functions as write or exists was working: they both was returning ok when finishing saving or checking if file exists, but I couldn't see the files in the File app. Since I have some apps installed on my device, I saw that everyone has his folder inside on My iPhone but mine didn't.

After 2 days spending on understanding what permissions do I need or what I'm doing wrong, I discovered that you need to explicitly indicate to iOS that your app is able to "expose" internal files, in order to make it visible inside File app. Solution is very easy: just add this lines into your info.plist file (located in ios folder in your react-native project):

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    ....
    <key>UIFileSharingEnabled</key>
    <true/>
    <key>LSSupportsOpeningDocumentsInPlace</key>
    <true/>
    <key>UISupportsDocumentBrowser</key>
    <true/>
</dict>
</plist>

This will indicate that your app is exposing file saved inside RNFS.DocumentDirectoryPath and user can access them with the File app.

It would be great to add this instruction to README.

BRAVOOOOOOOOOOO <3

ShaheerAliKhan avatar Jan 10 '23 19:01 ShaheerAliKhan

The thing is pretty straightforward. The guides on how to use RNFS do not explain carefully that iOS hides by default the files that you save. Every app in iOS has its "sandbox" when they can write/read without any major restrictions, but by default users aren't able to see any files. This could be potentially a problem if saved files are needed for the final user.

On Android this problem does not exist, since you can write, for example, in Download folder, if storage access is granted.

This was very unclear for me: the functions as write or exists was working: they both was returning ok when finishing saving or checking if file exists, but I couldn't see the files in the File app. Since I have some apps installed on my device, I saw that everyone has his folder inside on My iPhone but mine didn't.

After 2 days spending on understanding what permissions do I need or what I'm doing wrong, I discovered that you need to explicitly indicate to iOS that your app is able to "expose" internal files, in order to make it visible inside File app. Solution is very easy: just add this lines into your info.plist file (located in ios folder in your react-native project):

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    ....
    <key>UIFileSharingEnabled</key>
    <true/>
    <key>LSSupportsOpeningDocumentsInPlace</key>
    <true/>
    <key>UISupportsDocumentBrowser</key>
    <true/>
</dict>
</plist>

This will indicate that your app is exposing file saved inside RNFS.DocumentDirectoryPath and user can access them with the File app.

It would be great to add this instruction to README.

Thanks alot, you just saved my day <3

ahsuniqbal avatar Jan 10 '23 19:01 ahsuniqbal

thanks a lot. this really should be added in the readme

khanisak avatar May 26 '23 13:05 khanisak

I have one question. Do the files persist after performing an app update on iOS? I am currently using another library and after implementaion, I found out that the absolute paths to the files change whenever an update is performed through Testflight. Any ideas how to persist the paths to local files after updates? Thanks.

indeed applicationID is changes every time you update the app (TestFlight, build new release-scheme app locally, etc) - thus, if you are storing somewhere the full path to your file it will become invalid because your applicationID had changed. You either should always use dynamic value of RNFS.DocumentDirectoryPath or check is file exists every time you try to access it.

oharbo avatar Feb 28 '24 15:02 oharbo