【问题标题】:Titanium DocumentViewer not showing documentTitanium DocumentViewer 不显示文档
【发布时间】:2018-01-08 21:34:58
【问题描述】:

我的 appcelerator 合金应用程序有一个部分在列表视图中显示员工使用的协议列表(大约有 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();
}

显示查看器如何显示它的图像:

【问题讨论】:

标签: javascript titanium appcelerator


【解决方案1】:

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

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

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

【讨论】:

  • 这显示的内容比我以前使用的要多,它尝试加载 PDF 而不是仅显示文件名,但在短暂的加载图标后仍然会产生相同的结果。我最终做的是根据这个 appcelerator jira 中的测试代码将它加载到 web 视图中:jira.appcelerator.org/browse/TIMOB-25185
猜你喜欢
  • 2023-03-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-09-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多