【问题标题】:How Open downloaded files in ios with cordova?如何使用cordova在ios中打开下载的文件?
【发布时间】:2015-12-11 06:12:43
【问题描述】:

我在ios中完成了下载部分。

但是为了打开下载文件,我在 android 中使用了文件打开器插件,它在 android 中运行良好。但是对于 ios 文件打开器插件不起作用。

谁能帮帮我?在此先感谢:)。

【问题讨论】:

  • 需要更多关于错误的信息并链接到你正在使用的 ios 插件,还有 iOS 版本。
  • 您使用了哪个插件。试试this one
  • com.phonegap.fileopener 这个我用过。以下代码我用来在android window.plugins.fileOpener.open(decodeURI(entry.toURL()))中打开下载的文件;
  • @Nirus 这段代码在 android(window.plugins.fileOpener.open(decodeURI(entry.toURL()))) 中运行。但我正在 iphone 4s 和 5s 中测试 myapp。我不知道如何在iphone中调试。有什么方法可以在 web 浏览器中调试代码,例如 chrome for android。
  • @manukv 我正在设备上进行测试,如何查看设备上的错误。我是 ios 新手。

标签: ios cordova


【解决方案1】:

希望您使用的是旧的, 试试fileopener2

通过cli安装插件

cordova plugin add cordova-plugin-file-opener2

而且用法是

cordova.plugins.fileOpener2.open(
    '/sdcard/Download/mypdf.pdf', // You can also use a Cordova-style file uri: cdvfile://localhost/persistent/Download/starwars.pdf
    'application/pdf', 
    { 
        error : function(e) { 
            console.log('Error status: ' + e.status + ' - Error message: ' + e.message);
        },
        success : function () {
            console.log('file opened successfully');                
        }
    }
);

更新

您可以从 MIME 类型列表中指定 MIME 类型(第二个字段)。 这些是list of known MIME-types

【讨论】:

  • 是否需要传递第二个参数。就我而言,我有动态数据下载选项,它可能是 .pdf 或 .doc 或 .png。
  • 恐怕你没有回答奎师那的问题
猜你喜欢
  • 2021-04-23
  • 1970-01-01
  • 2014-03-23
  • 2016-08-01
  • 2017-10-16
  • 2021-01-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多