【发布时间】:2020-05-06 14:14:18
【问题描述】:
我正在尝试读取通过电子邮件发送然后下载到 iOS 设备的文本文件。具体来说,文本文件保存在 - “文件图标 - 在我的手机上”。
我正在使用以下插件 @ionic-native/file/ngx / cordova-plugin-file。我可以让它在 Android 上运行,但我不确定文件的位置或如何找到它?
我在以下 iOS 目录中使用了插件 checkDir() 来验证它们是否存在并且我可以使用已安装的插件:
cordova.file.tempDirectory - Temp directory that the OS can clear at will. Do not rely on the OS to clear this directory; your app should always remove files as applicable. ( iOS , OSX , windows )
cordova.file.syncedDataDirectory - Holds app-specific files that should be synced (e.g. to iCloud). ( iOS , windows )
cordova.file.documentsDirectory - Files private to the app, but that are meaningful to other application (e.g. Office files). Note that for OSX this is the user’s ~/Documents directory. ( iOS , OSX )
我想用下面的方法来访问和读入文本文件:
this.file.readAsText()
但如果我尝试访问每个目录中的文件 - 例如通过以下方式:
this.file.readAsText(this.file.tempDirectory, 'MyData.txt').then((data) => {})
由于无法找到文件而出错。
底线是我没有存储在我的 iOS 设备上的文本文件的正确路径。
任何有关如何确定保存在 iOS 设备上的文本文件路径的帮助将不胜感激。
谢谢
【问题讨论】:
-
检查此链接,它应该可以解决您的问题,它会向您显示图像的正常部分:
-
感谢您的回复。在您提供的链接中,他们似乎指定了文件的下载位置 - cordova.file.dataDirectory 。就我而言,我从 iPhone 上的 gmail 帐户下载了一个文本文件。查看它存储在的 iPhone - 文件图标 - “在我的 iPhone 上”,我不知道该位置的路径?正如我在下面提到的,我尝试在以下位置读取文件,documentsDirectory、dataDirectory、syncedDataDirectory、cacheDirectory、tempDirectory per github.com/apache/cordova-plugin-file#file-system-layouts,但找不到该文件。
-
你可以手动访问文件吗?
-
在 iPhone 上,我可以转到“文件”图标,然后在“我的 iPhone”下看到文本文件。我可以双击它并打开它。例如,当我尝试使用 this.file.readAsText(this.file.documentsDirectory, 'MyData.txt').then((data) => {})。找不到。我不确定如何找出文件的路径?
标签: android ios angular cordova ionic-framework