我的 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();
}
最佳答案
我想您只是想在 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/