Titanium JIRA Archive
Appcelerator Community (AC)

[AC-6038] iOS: Ti.WKWebView cannot load local files or images

GitHub Issuen/a
TypeBug
Priorityn/a
StatusResolved
ResolutionHold
Resolution Date2018-12-23T22:29:58.000+0000
Affected Version/sn/a
Fix Version/sn/a
Componentsn/a
Labelsn/a
ReporterMatthew Delmarter
AssigneeShak Hossain
Created2018-11-28T01:55:42.000+0000
Updated2019-02-14T23:46:49.000+0000

Description

We are supposed to be replacing the use of UIWebView with WKWebView on iOS, but this is proving to be impossible for me as I cannot figure out how to load local resources such as images, JS or CSS files from the Resources directory or from the applicationDir or tempDir. I cannot find any evidence of this being possible. If it is possible, can some working sample code please be provided. Otherwise could support for this please be added urgently as this is a major limitation. *Sample code* Using a UIWebView the following code works:
var win = Ti.UI.createWindow({
  backgroundColor: 'white'
});

var html = '<img src="app://Resources/abc.jpg">';

var webview = Ti.UI.createWebView({
  html: html
});

win.add(webview);
win.open();
Note that in tiapp.xml is set to false so that the image can be referenced. The same code using WKWebView does not load the image. Changing the image src to use the native file path also does not work.

Comments

  1. Vijay Singh 2018-11-28

    Hi Matthew, In jira ticket TIMOB-26095, we have already made a [PR](https://github.com/appcelerator/titanium_mobile/pull/10169) for moving to WKWebView from UIWebView, which will go in 8.0.0. [This commit](https://github.com/appcelerator/titanium_mobile/pull/10169/commits/ea7bee7cb3f155d2df1b7f5de6b81da48f4ad3e8) is responsible for handling local file in TIUIWebView which is missing in Ti.WKWebView. Would you like to test your app with above PR. If it works I'll move this code in Ti.WKWebView as well. Thanks!
  2. Matthew Delmarter 2018-11-28

    Hi Vijay that is great news and I will certainly test out the PR tomorrow. Thanks for sharing the details.
  3. Matthew Delmarter 2018-11-28

    Hi @vijaysingh I am currently using 7.5.0.GA and the changeset you pointed me is not synonomous as there have been other changes made to TiUIWebView.m in 8.0 outside of just that one changeset. So instead I have switched to experimenting with SDK build 8.0.0.v20181030074154. In testing this, my understanding is that 8.0 will continue to support calls to Ti.UI.createWebView - and it will be switching to use WKWebView under the hoods ... is that correct? So basically I should ignore the module version of WKWebView and just work with Ti.UI.createWebView and it will be taken care of under the hoods? I tracked down what looks like the updated docs around these changes [here](https://github.com/appcelerator/titanium_mobile/blob/3728533ad0938f86bab1780514afd7f5a47ed5c0/apidoc/Titanium/UI/WebView.yml). Also is there an expected timeframe for a 8.0 RC or GA? i.e. is there a target before the end of the year? Or should I not count on this? Thanks for your help.
  4. Vijay Singh 2018-11-29

    [~mdelmarter] Yes. From sdk 8.0.0+ Ti.UI.createWebView will internally use WKWebView apis instead UIWebView. And it is 100% backward compatible. So you do not have to change anything in your code, if you are using TiUiWebView. I do not have any release date with me. I guess it can be in next 2 weeks. Thanks!
  5. Matthew Delmarter 2018-11-29

    @vijay Thanks so much for your clear explanation that is really helpful.
  6. Matthew Delmarter 2019-02-14

    Just FYI I have been trying to experiment with the Ti SDK 8.0 to verify that this code should work, but it does not seem to for me. I last used build 8.0.0.v20190130052111. I am anxiously waiting for 8.0 and verification of this code working. I am building a new app that heavily uses WebView and I am greatly concerned about the change to WKWebView and the amount of things that may break.

JSON Source