{ "id": "170807", "key": "TIMOB-25680", "fields": { "issuetype": { "id": "1", "description": "A problem which impairs or prevents the functions of the product.", "name": "Bug", "subtask": false }, "project": { "id": "10153", "key": "TIMOB", "name": "Titanium SDK/CLI", "projectCategory": { "id": "10100", "description": "Titanium and related SDKs used in application development", "name": "Client" } }, "fixVersions": [ { "id": "20060", "description": "", "name": "Release 7.0.2", "archived": false, "released": true, "releaseDate": "2018-02-09" } ], "resolution": { "id": "1", "description": "A fix for this issue is checked into the tree and tested.", "name": "Fixed" }, "resolutiondate": "2018-01-23T16:44:58.000+0000", "created": "2018-01-17T02:01:12.000+0000", "priority": { "name": "High", "id": "2" }, "labels": [ "applebug", "documentViewer", "ios" ], "versions": [ { "id": "19988", "description": "", "name": "Release 7.0.1", "archived": false, "released": true, "releaseDate": "2017-12-21" } ], "issuelinks": [ { "id": "56263", "type": { "id": "10003", "name": "Relates", "inward": "relates to", "outward": "relates to" }, "outwardIssue": { "id": "170922", "key": "TIMOB-25702", "fields": { "summary": "iOS: Remove iOS 11.2 DocumentViewer workaround", "status": { "description": "The issue is open and ready for the assignee to start work on it.", "name": "Open", "id": "1", "statusCategory": { "id": 2, "key": "new", "colorName": "blue-gray", "name": "To Do" } }, "priority": { "name": "Medium", "id": "3" }, "issuetype": { "id": "4", "description": "An improvement or enhancement to an existing feature or task.", "name": "Improvement", "subtask": false } } } } ], "assignee": { "name": "hknoechel", "key": "hansknoechel", "displayName": "Hans Knöchel", "active": true, "timeZone": "Europe/Berlin" }, "updated": "2018-01-24T16:22:40.000+0000", "status": { "description": "The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.", "name": "Closed", "id": "6", "statusCategory": { "id": 3, "key": "done", "colorName": "green", "name": "Done" } }, "components": [ { "id": "10206", "name": "iOS", "description": "iOS Platform" } ], "description": "Issue\r\nUsing DocumentViewer on iOS 11.2.X is not rendering PDF files.\r\n\r\nSteps to repro\r\n1. Just run the following test code \r\n2. At first, place a pdf file in the resource directory.\r\n\r\nExpected result:\r\n .pdf file should show in the DocumentViewer.\r\n\r\nActual result:\r\n .pdf file is not being shown by the DocumentViewer.\r\n\r\n{code:js}\r\nvar win = Ti.UI.createWindow();\r\n\r\n// Create a document viewer to preview a PDF file\r\ndocViewer = Ti.UI.iOS.createDocumentViewer({\r\n url : 'example.pdf'\r\n});\r\n\r\ndocViewer.show();\r\nwin.open();\r\n\r\n{code}\r\n", "attachment": [ { "id": "63974", "filename": "example.pdf", "author": { "name": "hknoechel", "key": "hansknoechel", "displayName": "Hans Knöchel", "active": true, "timeZone": "Europe/Berlin" }, "created": "2018-01-17T09:45:54.000+0000", "size": 433994, "mimeType": "application/pdf" } ], "flagged": false, "summary": "iOS 11.2: DocumentViewer not displaying PDF files (Apple regression)", "creator": { "name": "morahman", "key": "morahman", "displayName": "Motiur Rahman", "active": true, "timeZone": "Asia/Dhaka" }, "subtasks": [], "reporter": { "name": "morahman", "key": "morahman", "displayName": "Motiur Rahman", "active": true, "timeZone": "Asia/Dhaka" }, "environment": "Operating System\r\n Name = Mac OS X\r\n Version = 10.13.2\r\nNode.js\r\n Node.js Version = 8.9.3\r\n npm Version = 5.5.1\r\nTitanium CLI\r\n CLI Version = 5.0.14\r\nTitanium SDK\r\n SDK Version = 6.3.0.GA, 7.0.1.GA\r\n Target Platform = iphone 5s v11.2.2", "comment": { "comments": [ { "id": "433244", "author": { "name": "hknoechel", "key": "hansknoechel", "displayName": "Hans Knöchel", "active": true, "timeZone": "Europe/Berlin" }, "body": "*EDIT*: There seems to be a breaking change in 11.2 that developers came across (known iOS issue). Basically, iOS 11.2 required developers to copy the PDF to the temporary- or application-support directory before using. Read more about it [here|https://forums.developer.apple.com/thread/91835].\r\n\r\nWe will:\r\n# File a radar at Apple to provide a fix\r\n# Provide a workaround (eventually in both JS and the SDK, so an SDK-update won't necessarily required to workaround this issue)\r\n\r\nTested with all possible combinations (main-thread, kroll-thread, jscore, ticore) and it works fine. My example code:\r\n{code:js}\r\nvar win = Ti.UI.createWindow({\r\n backgroundColor: '#fff'\r\n});\r\n\r\nvar btn = Ti.UI.createButton({\r\n title: 'Open PDF'\r\n});\r\n\r\nbtn.addEventListener('click', function(e) {\r\n var docViewer = Ti.UI.iOS.createDocumentViewer({\r\n url : 'example.pdf'\r\n });\r\n \r\n docViewer.show();\r\n});\r\n\r\nwin.add(btn);\r\nwin.open();\r\n{code}\r\n\r\nI've also attached my sample PDF file that worked fine. As a side-note: We haven't touched the DocumentViewer API for years, since it's a simple interface which we completely expose already.", "updateAuthor": { "name": "hknoechel", "key": "hansknoechel", "displayName": "Hans Knöchel", "active": true, "timeZone": "Europe/Berlin" }, "created": "2018-01-17T09:46:13.000+0000", "updated": "2018-01-17T09:52:35.000+0000" }, { "id": "433247", "author": { "name": "hknoechel", "key": "hansknoechel", "displayName": "Hans Knöchel", "active": true, "timeZone": "Europe/Berlin" }, "body": "h2. Update\r\n\r\nHere is the workaround for the iOS issue, together with detailed documentation about what is happening:\r\n\r\n{code:js}\r\nvar win = Ti.UI.createWindow({\r\n backgroundColor: '#fff'\r\n});\r\n\r\nvar btn = Ti.UI.createButton({\r\n title: 'Open PDF'\r\n});\r\n\r\nbtn.addEventListener('click', openPDF);\r\n\r\nwin.add(btn);\r\nwin.open();\r\n\r\n// Open the PDF file\r\nfunction openPDF() {\r\n var fileName = 'example.pdf';\r\n \r\n // For iOS 11.2, workaround the Apple issue by creating a temporary file and\r\n // reference it. It will be removed from filesystem once the app closes.\r\n // Read more here: http://nshipster.com/nstemporarydirectory/\r\n if (isiOS11_2()) {\r\n fileName = fileInTemporaryDirectory(fileName);\r\n }\r\n \r\n var docViewer = Ti.UI.iOS.createDocumentViewer({\r\n url: fileName\r\n });\r\n \r\n docViewer.show();\r\n}\r\n\r\n// Check if the current device runs iOS 11.2+\r\nfunction isiOS11_2() {\r\n\tvar version = Ti.Platform.version.split(\".\");\t\r\n\treturn (parseInt(version[0]) >= 11 && parseInt(version[1]) >= 2);\r\n}\r\n\r\n// Create a temporary file with the contents of the old file\r\n// Expects the file to be in the resources directory. If you receive the file \r\n// from an API-call, receive pass the Ti.Blob/Ti.File/text to \"write\" directly.\r\nfunction fileInTemporaryDirectory(fileName) {\r\n var file = Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory, fileName);\r\n \r\n if (!file.exists()) {\r\n alert('File does not exist in resources!');\r\n return;\r\n }\r\n \r\n var newFile = Titanium.Filesystem.getFile(Ti.Filesystem.tempDirectory, fileName);\r\n newFile.createFile();\r\n \r\n if (!newFile.exists()) {\r\n alert('New file could not be created in temporary directory!');\r\n return;\r\n }\r\n \r\n newFile.write(file);\r\n \r\n return newFile.nativePath;\r\n}\r\n{code}\r\n\r\nBasically, we create a temporary file in /tmp that will be flushed once the app is closed, so it doesn't effect the device's storage. Keeping this issue open to also provide an SDK workaround that detects the type of path provided and fixes it internally. Hopefully iOS fixes this issue in iOS 11.2.x, but let's try to keep as flexible as possible.", "updateAuthor": { "name": "hknoechel", "key": "hansknoechel", "displayName": "Hans Knöchel", "active": true, "timeZone": "Europe/Berlin" }, "created": "2018-01-17T10:25:31.000+0000", "updated": "2018-01-17T10:25:31.000+0000" }, { "id": "433249", "author": { "name": "hknoechel", "key": "hansknoechel", "displayName": "Hans Knöchel", "active": true, "timeZone": "Europe/Berlin" }, "body": "PR (master): https://github.com/appcelerator/titanium_mobile/pull/9741\r\nPR (7_0_X): https://github.com/appcelerator/titanium_mobile/pull/9742\r\n\r\nTest-Case:\r\n# Run the above test-case and remove the comment out the {{isiOS11_2()}} check. Without this line, the PDF will not be displayed\r\n# Comment it in the line if-statement again. It should now work, even with the old SDK (master/7.0.1)\r\n# Now uninstall the app, use the PR and repeat steps 1 und 2. They should still display the file without issues\r\n\r\n", "updateAuthor": { "name": "hknoechel", "key": "hansknoechel", "displayName": "Hans Knöchel", "active": true, "timeZone": "Europe/Berlin" }, "created": "2018-01-17T11:09:15.000+0000", "updated": "2018-01-17T11:09:15.000+0000" }, { "id": "433526", "author": { "name": "ewieber", "key": "ewieber", "displayName": "Eric Wieber", "active": false, "timeZone": "America/Los_Angeles" }, "body": "FR Passed. Workaround is working as designed. Document viewer is able to display PDF files in iOS 11.X", "updateAuthor": { "name": "ewieber", "key": "ewieber", "displayName": "Eric Wieber", "active": false, "timeZone": "America/Los_Angeles" }, "created": "2018-01-23T16:44:58.000+0000", "updated": "2018-01-23T16:44:58.000+0000" }, { "id": "433591", "author": { "name": "ewieber", "key": "ewieber", "displayName": "Eric Wieber", "active": false, "timeZone": "America/Los_Angeles" }, "body": "Verified in SDK builds 7.0.2.v20180123170142 & 7.1.0.v20180124063413", "updateAuthor": { "name": "ewieber", "key": "ewieber", "displayName": "Eric Wieber", "active": false, "timeZone": "America/Los_Angeles" }, "created": "2018-01-24T16:22:40.000+0000", "updated": "2018-01-24T16:22:40.000+0000" } ], "maxResults": 6, "total": 6, "startAt": 0 } } }