Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Martinocom opened this issue Sep 8, 2022 · 6 comments

Comments

@Martinocom
Copy link

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.

@Vick-Bay
Copy link

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.

@Martinocom
Copy link
Author

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 :)

@ShaheerAliKhan
Copy link

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

@ahsuniqbal
Copy link

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

@khanisak
Copy link

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

@oharbo
Copy link

oharbo commented Feb 28, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants