简体   繁体   English

如何在iOS模拟器中查看文档目录?

[英]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. 我编写了一个React Native应用程序,该应用程序下载文件并将其保存到文档目录中。

The application gives me a path like this: 该应用程序给了我这样的路径:

/Users/laurent/Library/Developer/CoreSimulator/Devices/SOMEID/data/Containers/Data/Application/SOMEID/Documents /用户/洛伦特/图书馆/开发人员/ CoreSimulator /设备/ SOMEID /数据/容器/数据/应用程序/ SOMEID /文档

and using macOS Finder I can see that the file has indeed been created. 并使用macOS Finder,我可以看到该文件确实已创建。

My problem is how to view this file from the iOS emulator? 我的问题是如何从iOS模拟器查看此文件? 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. 您的iOS应用默认为沙盒,这意味着没有其他应用可以访问其资源。 The simulator is very different since it runs on your mac and stores your files there so you can easily access them. 该模拟器与众不同,因为它在Mac上运行并将文件存储在此处,因此您可以轻松访问它们。

That said, it is very simple to expose your Documents folder by adding the appropriate keys to your app's info.plist : 也就是说,通过在应用程序的info.plist添加适当的键来公开Documents文件夹非常简单:

  • 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). 添加UISupportsDocumentBrowser键以授予对应用程序“文档”目录中所有文档的访问权限,并使它们显示在“文件”应用程序(iOS 11及更高版本)中。 When this is enabled, other apps can also have access to your documents when using UIDocumentBrowserViewController . 启用此功能后,其他应用程序在使用UIDocumentBrowserViewController时也可以访问您的文档。
  • Add the UIFileSharingEnabled key to expose the app's Documents directory to the desktop iTunes app. 添加UIFileSharingEnabled键,以将应用程序的Documents目录公开到桌面iTunes应用程序。 When combined with the LSSupportsOpeningDocumentsInPlace key, it will also enable Files app support and document browser as mentioned above. LSSupportsOpeningDocumentsInPlace键结合使用时,它还将启用如上所述的“文件”应用程序支持和文档浏览器。

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. 据我所知,没有可用于访问iOS文件系统的react-native库,因此您将需要使用本机iOS代码来解决问题。 Besides pointing you to the official documentation , there is not much more I can do to help. 除了为您提供官方文档外 ,我无能为力。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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