[AC-6428] iOS13: DocumentViewer not working
| GitHub Issue | n/a | 
|---|---|
| Type | Bug | 
| Priority | n/a | 
| Status | Open | 
| Resolution | Unresolved | 
| Affected Version/s | n/a | 
| Fix Version/s | n/a | 
| Components | n/a | 
| Labels | iOS13 | 
| Reporter | Thomas Weber | 
| Assignee | Shak Hossain | 
| Created | 2019-11-09T22:32:21.000+0000 | 
| Updated | 2019-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
| File | Date | Size | 
|---|---|---|
| screenshot.jpg | 2019-11-09T22:30:54.000+0000 | 199693 | 
The issue is the hard coded workaround:
This would returnfalsefor 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.[~tw] can you confirm it works if you follow [~hknoechel]'s instruction?
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