Titanium JIRA Archive
Appcelerator Community (AC)

[AC-6428] iOS13: DocumentViewer not working

GitHub Issuen/a
TypeBug
Priorityn/a
StatusOpen
ResolutionUnresolved
Affected Version/sn/a
Fix Version/sn/a
Componentsn/a
LabelsiOS13
ReporterThomas Weber
AssigneeShak Hossain
Created2019-11-09T22:32:21.000+0000
Updated2019-11-12T10:32:02.000+0000

Description

Using Ti SDK 8.2.0GA and iOS13.2 Simulator Titanium.UI.iOS.DocumentViewer is not showing any document, but only displays filename and filetype. Running on iOS11.0.1 Simulator it works as expected.

var win = Ti.UI.createWindow({
  backgroundColor: '#fff'
});
 
var btn = Ti.UI.createButton({
  title: 'Open PDF'
});
 
btn.addEventListener('click', openPDF);
 
win.add(btn);
win.open();
 
// Open the PDF file
function openPDF() {
  var fileName = 'example.pdf';
  
  // For iOS 11.2, workaround the Apple issue by creating a temporary file and
  // reference it. It will be removed from filesystem once the app closes.
  // Read more here: http://nshipster.com/nstemporarydirectory/
  if (isiOS11_2()) {
    fileName = fileInTemporaryDirectory(fileName);
  }
  
  var docViewer = Ti.UI.iOS.createDocumentViewer({
    url: fileName
  });
 
  docViewer.show();
}
 
// Check if the current device runs iOS 11.2+
function isiOS11_2() {
	var version = Ti.Platform.version.split(".");	
	return (parseInt(version[0]) >= 11 && parseInt(version[1]) >= 2);
}
 
// Create a temporary file with the contents of the old file
// Expects the file to be in the resources directory. If you receive the file 
// from an API-call, receive pass the Ti.Blob/Ti.File/text to "write" directly.
function fileInTemporaryDirectory(fileName) {
  var file = Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory, fileName);
  
  if (!file.exists()) {
    alert('File does not exist in resources!');
    return;
  }
  
  var newFile = Titanium.Filesystem.getFile(Ti.Filesystem.tempDirectory, fileName);
  newFile.createFile();
  
  if (!newFile.exists()) {
    alert('New file could not be created in temporary directory!');
    return;
  }
  
  newFile.write(file);
  
  return newFile.nativePath;
}

Attachments

FileDateSize
screenshot.jpg2019-11-09T22:30:54.000+0000199693

Comments

  1. Hans Knöchel 2019-11-11

    The issue is the hard coded workaround:
       return (parseInt(version[0]) >= 11 && parseInt(version[1]) >= 2);
       
    This would return false for iOS 12.1 and iOS 13.1. Instead, just check for iOS >= 11 or don't check at all, since caching the PDF for later file access is always a good idea.
  2. Rene Pot 2019-11-12

    [~tw] can you confirm it works if you follow [~hknoechel]'s instruction?
  3. Thomas Weber 2019-11-12

    Ok, it probably was not the best idea to simply copy the example code, but the simulator problem can also be reproduced with this example: {{var file = Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory, "test.pdf"); var docViewer = Ti.UI.iOS.createDocumentViewer({ url: file.resolve() }); docViewer.show();}} Simulator iOS 13.2 / Only shows filename and filetype (as on the screenshot) MacOS 10.14.6 / Xcode 11.2 Simulator iOS 11.0.1 / works MacOS 10.14.6 / Xcode 11.2 Device iOS 13.2 / works

JSON Source