ionic 4-使用@ ionic-native/file/ngx/cordova-plugin-file访问iOS文件 [英] ionic 4 - iOS file access with @ionic-native/file/ngx/cordova-plugin-file

查看:317
本文介绍了ionic 4-使用@ ionic-native/file/ngx/cordova-plugin-file访问iOS文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试读取通过电子邮件发送的文本文件,然后将其下载到iOS设备.具体来说,文本文件保存在-文件图标-在我的手机上".

I am trying to read in a text file that is sent via e-mail and then downloaded to an iOS device. Specifically the text file is saved in - "Files icon - On My Phone".

我正在使用以下插件@ ionic-native/file/ngx / cordova-plugin-file .我可以在Android上使用它,但是我不确定文件的位置或如何找到它?

I am using the following plugin @ionic-native/file/ngx / cordova-plugin-file. I am able to get this to work on Android but I am not sure of the to the location of the file or how to find it?

我已使用以下iOS目录上的插件 checkDir()来验证它们是否存在以及我是否可以使用已安装的插件:

I have used the plugins checkDir() on the following iOS directories to verify that they exist and that I can use the installed plugin:

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 )

我想使用以下方法访问和读取文本文件:

I want to use the following method to access and read in the text file:

this.file.readAsText()

但是,如果我尝试访问每个目录中的文件-例如,通过以下命令:

But if I try to access the file in each of these directories - for example via the following:

this.file.readAsText(this.file.tempDirectory, 'MyData.txt').then((data) => {})

由于找不到文件而出错.

It errors out with not being able to locate the file.

最重要的是,我没有存储在iOS设备上的文本文件的正确路径.

Bottom line is I do not have the correct path to the text file stored on my iOS device.

对于确定如何保存到iOS设备上的文本文件的路径的任何帮助,将不胜感激.

Any help on how to determine the path to my text file saved on an iOS device would be greatly appreciated.

谢谢

推荐答案

我将参考插件的github文件位置参考:

I would refer to the plugin's github file locations reference: https://github.com/apache/cordova-plugin-file#file-system-layouts

然后从电子邮件中保存后检查此类.txt的实际存储位置(我认为这也可能取决于所使用的电子邮件客户端以及特别是您打算支持的iOS版本)

Then check where actually such .txt gets stored after you save it from email (I think it might also depend on which email client is used and which iOS version, in particular, you intend to support)

更新: 对于IOS,特别是应该通过config.xml添加文件共享权限:

Update: for IOS specifically one should add file sharing permission via config.xml:

<key>UIFileSharingEnabled</key>
<true/>

这篇关于ionic 4-使用@ ionic-native/file/ngx/cordova-plugin-file访问iOS文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆