{ "id": "175266", "key": "AC-6568", "fields": { "issuetype": { "id": "1", "description": "A problem which impairs or prevents the functions of the product.", "name": "Bug", "subtask": false }, "project": { "id": "12217", "key": "AC", "name": "Appcelerator - INBOX", "projectCategory": { "id": "10000", "description": "", "name": "Customer Service" } }, "resolution": null, "resolutiondate": null, "created": "2020-07-07T12:40:57.000+0000", "labels": [], "versions": [], "issuelinks": [], "assignee": { "name": "amukherjee", "key": "amukherjee", "displayName": "Abir Mukherjee", "active": true, "timeZone": "America/Los_Angeles" }, "updated": "2020-07-21T08:01:56.000+0000", "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" } }, "components": [ { "id": "14548", "name": "Titanium SDK & CLI", "description": "Please enter tickets related to the MobileSDK here." } ], "description": "*Summary*\r\n\r\nI'm downloading some images from the internet and storing them in the Ti.Filesystem.applicationDataDirectory. Since WKWebView was introduced we can no longer access the application directory directly, but I thought we could work around this by setting the baseURL in the second parameter of WebView.setHTML.\r\n\r\n*Step to reproduce*\r\n\r\n# Add the example code to a Titanium classic project\r\n# Set the SDK to 9.0.3.GA\r\n# Run the app on iOS and wait for the webview to load (black content)\r\n\r\n{code:java}\r\nconst window = Ti.UI.createWindow();\r\nconst wv = Ti.UI.createWebView();\r\nwindow.add(wv);\r\n\r\nfunction getContentDir() {\r\n var dir = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory, 'content/');\r\n if (!dir.exists()) {\r\n dir.createDirectory();\r\n }\r\n return dir;\r\n}\r\n\r\nfunction getImage() {\r\n const contentDir = getContentDir();\r\n return Ti.Filesystem.getFile(contentDir.nativePath, 'image.png');\r\n}\r\n\r\nfunction request() {\r\n return new Promise(function (resolve, reject) {\r\n const req = Ti.Network.createHTTPClient({\r\n onload: () => {\r\n resolve(req.responseData);\r\n },\r\n onerror: (error) => {\r\n reject(error);\r\n },\r\n timeout: 15000\r\n });\r\n\r\n req.open(\"GET\", \"https://www.appcelerator.com/wp-content/uploads/Axway_logo_horiz_clr_rev_rgb.png\");\r\n req.send(null);\r\n });\r\n}\r\n\r\nfunction getWrappedHTML(bodyContent) {\r\n return `\r\n \r\n \r\n \r\n \r\n \r\n \r\n
${bodyContent}
\r\n \r\n `;\r\n}\r\n\r\nfunction loadImage() {\r\n console.log(getContentDir().nativePath);\r\n // setHtml with baseURL\r\n wv.setHtml(getWrappedHTML(``), { baseURL : getContentDir().nativePath });\r\n}\r\n\r\nwindow.addEventListener('open', () => {\r\n const image = getImage();\r\n\r\n if (image.exists()) {\r\n loadImage(image);\r\n } else {\r\n request().then((response) => {\r\n image.write(response);\r\n loadImage(image);\r\n }).catch((error) => {\r\n console.log(error);\r\n });\r\n } \r\n});\r\n\r\nwindow.open();\r\n{code}\r\n\r\n*Expected result*\r\n\r\nThe webview shows the axway logo on a black background.\r\n\r\n*Actual result*\r\n\r\nThe webview shows a black background with a missing image.\r\n", "attachment": [], "flagged": false, "summary": "iOS: WebView.setHtml with baseURL doesn't seem to work correctly", "creator": { "name": "teunklijn@telfort.nl", "key": "teunklijn@telfort.nl", "displayName": "Teun Klijn", "active": true, "timeZone": "Europe/Amsterdam" }, "subtasks": [], "reporter": { "name": "teunklijn@telfort.nl", "key": "teunklijn@telfort.nl", "displayName": "Teun Klijn", "active": true, "timeZone": "Europe/Amsterdam" }, "environment": "Ti SDK 9.0.0.GA", "comment": { "comments": [ { "id": "456014", "author": { "name": "jquick", "key": "jquick", "displayName": "Joshua Quick", "active": true, "timeZone": "America/Los_Angeles" }, "body": "As of 9.0.0, the {{WebView}} has a new \"assetsDirectory\" property. Set it to the same directory as your \"baseURL\".\r\nhttps://docs.appcelerator.com/platform/latest/#!/api/Titanium.UI.WebView-property-assetsDirectory\r\n\r\nThis is a security feature in Apple's {{WKWebView}}. You have to give it permission to access files from local storage by setting this property.\r\n", "updateAuthor": { "name": "jquick", "key": "jquick", "displayName": "Joshua Quick", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2020-07-07T15:48:35.000+0000", "updated": "2020-07-07T15:48:35.000+0000" }, { "id": "456020", "author": { "name": "teunklijn@telfort.nl", "key": "teunklijn@telfort.nl", "displayName": "Teun Klijn", "active": true, "timeZone": "Europe/Amsterdam" }, "body": "Thank you for your feedback, but it still doesn't work when I set the assetsDirectory. This does work when I set the url property instead using setHtml, but I don't want to use html files. The strange thing is that I don't even see the image on a simulator, and I think a simulator does have access to the application directory without setting the assetsDirectory right?", "updateAuthor": { "name": "teunklijn@telfort.nl", "key": "teunklijn@telfort.nl", "displayName": "Teun Klijn", "active": true, "timeZone": "Europe/Amsterdam" }, "created": "2020-07-08T07:25:39.000+0000", "updated": "2020-07-08T07:25:39.000+0000" }, { "id": "456131", "author": { "name": "teunklijn@telfort.nl", "key": "teunklijn@telfort.nl", "displayName": "Teun Klijn", "active": true, "timeZone": "Europe/Amsterdam" }, "body": "Is there any update on this?", "updateAuthor": { "name": "teunklijn@telfort.nl", "key": "teunklijn@telfort.nl", "displayName": "Teun Klijn", "active": true, "timeZone": "Europe/Amsterdam" }, "created": "2020-07-16T14:52:40.000+0000", "updated": "2020-07-16T14:52:40.000+0000" }, { "id": "456176", "author": { "name": "vijaysingh", "key": "vijaysingh", "displayName": "Vijay Singh", "active": true, "timeZone": "America/Los_Angeles" }, "body": "[~teunklijn@telfort.nl] See discussion in TIMOB-27064. Probably it will help you. \r\nSo -\r\n1. It is limitation from WKWebView.\r\n2. Either you can use base64 encoding of image in your html text (example is given in comment section of TIMOB-27064) Or\r\n3. Write your html data in a file and use in combination with assetsDirectory (again example is in comment section of TIMOB-27064)\r\n\r\nThanks!", "updateAuthor": { "name": "vijaysingh", "key": "vijaysingh", "displayName": "Vijay Singh", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2020-07-20T19:29:21.000+0000", "updated": "2020-07-20T19:29:21.000+0000" }, { "id": "456180", "author": { "name": "teunklijn@telfort.nl", "key": "teunklijn@telfort.nl", "displayName": "Teun Klijn", "active": true, "timeZone": "Europe/Amsterdam" }, "body": "Ok thanks! I was already using the base64 method, so I guess I'll keep using that.", "updateAuthor": { "name": "teunklijn@telfort.nl", "key": "teunklijn@telfort.nl", "displayName": "Teun Klijn", "active": true, "timeZone": "Europe/Amsterdam" }, "created": "2020-07-21T08:01:56.000+0000", "updated": "2020-07-21T08:01:56.000+0000" } ], "maxResults": 5, "total": 5, "startAt": 0 } } }