我试图读取通过电子邮件发送的文本文件,然后下载到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设备上保存的路径的帮助。
谢谢
最佳答案
我将参考插件的github文件位置参考:https://github.com/apache/cordova-plugin-file#file-system-layouts
然后,从电子邮件中保存后检查此类.txt的实际存储位置(我认为它也可能取决于所使用的电子邮件客户端以及特定的iOS版本)
更新:
对于IOS,尤其应该通过config.xml添加文件共享权限:
<key>UIFileSharingEnabled</key>
<true/>