简体   繁体   中英

How to view document directory in iOS emulator?

I wrote a React Native application that downloads a file and saves it to the document directory.

The application gives me a path like this:

/Users/laurent/Library/Developer/CoreSimulator/Devices/SOMEID/data/Containers/Data/Application/SOMEID/Documents

and using macOS Finder I can see that the file has indeed been created.

My problem is how to view this file from the iOS emulator? If I click on the Files app for instance, I can't see that file. Basically is this file available to the user from somewhere and, if so, where? Or maybe I need to save it to a different directory?

Your iOS app is sandboxed by default, meaning that no other app can access its resources. The simulator is very different since it runs on your mac and stores your files there so you can easily access them.

That said, it is very simple to expose your Documents folder by adding the appropriate keys to your app's info.plist :

  • Add the UISupportsDocumentBrowser key to grants access to all the documents in the app's Documents directory and have them appear in the Files app (iOS 11 and above). When this is enabled, other apps can also have access to your documents when using UIDocumentBrowserViewController .
  • Add the UIFileSharingEnabled key to expose the app's Documents directory to the desktop iTunes app. When combined with the LSSupportsOpeningDocumentsInPlace key, it will also enable Files app support and document browser as mentioned above.

By default any files your application downloads are only available from within that app, they will not show up in the file system of the device.

As far as I know there is no react-native library which allows you to access the iOS file system, so you will need to make use of native iOS code to solve your problem. Besides pointing you to the official documentation , there is not much more I can do to help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM