javascript - Titanium DocumentViewer 不显示文档

标签 javascript titanium appcelerator

我的 appcelerator alloy 应用程序有一个部分在 ListView 中显示员工使用的协议(protocol)列表(大约有 25 个),当点击一行时,它应该在 assets/protocol_pdf 文件夹中打开相应的 PDF 文档。在 iOS 11.2.1 中,文档查看器打开,但不显示 PDF,仅显示文件名后跟 PDF 文档(见图片)。在 iOS 10 及之前的版本中一切正常。

我使用了 http://www.appcelerator.com/blog/2015/08/appcelerator-pdf-viewer-demo/ 中的代码示例打开 PDF。

此外,在新的测试项目中使用 appcelerator 文档 (http://docs.appcelerator.com/platform/latest/#!/api/Titanium.UI.iOS.DocumentViewer) 中的确切代码会导致同样的问题。

此时我不确定如何解决该问题。我只能猜测文件的保存位置和访问方式有所不同。任何建议表示赞赏。

我的代码:

function onItemClick(e){    
    var item = $.listView.sections[e.sectionIndex].items[e.itemIndex];

    Ti.API.info('Opening ' + item.properties.file);
    if(OS_IOS){
        openResourcePDF(item.properties.file);
    } else{
        Alloy.Globals.Navigator.open("androidPDF", {file: item.properties.file});
    }
}

function openResourcePDF(fileName){
    var appFile;
    appFile = Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory, fileName);

    var appfilepath = appFile.nativePath;
    viewPDF(appfilepath);
}

function viewPDF(appfilepath){
    docViewer = Ti.UI.iOS.createDocumentViewer({url:appfilepath});
    docViewer.show();
}

显示查看器如何调出它的图像: enter image description here

最佳答案

我想您只是想在 iOS 上使用它。试试这个:

function openResourcePDF(fileName) {
    var appFile;
    appFile = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory, fileName);

    var appfilepath = appFile.nativePath;
    viewFile(appfilepath);
}

关于javascript - Titanium DocumentViewer 不显示文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48158385/

相关文章:

java - 将 Visual Studio Code 与 Titanium 结合使用时出现 "JDK (Java Development Kit) not Installed"

javascript - 行点击数据表

ios - Titanium:设置最低 iOS 版本

javascript - 使用 React 和 React-bootstrap 应用程序进行不必要的模态渲染

swift - 如何使用 Swift 制作 appcelerator ios 原生模块?

javascript - 如何使 Titanium TextArea 中的单词变为粗体或斜体

android - iOS - 从应用程序内调用 Web 应用程序

ios - Appcelerator Titanium map View - 默认显示注释标题

Javascript 显示/隐藏多个 DIV

javascript - 使用 OAuth 将 REST 调用从 Node 服务器发送到第三方应用程序