Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

WKWebview
Started by cublah Dec 19 2019 01:18 AM

18 replies to this topic
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

cublah

[GLOBAL: userInfoPane.html]
cublah
  • Contributor

  • 393 posts
  • Corona SDK

So I noticed uiwebview was upgraded to WKWebview which is great, it’s much faster with the nitro JavaScript engine in iOS, although I have a problem I want to run a web page from the documents directory and it doesn’t seem to work, on investigation into the source code I see that when initializing the web view there is no configuration set to allow this, to make this work how can I get this added to the core source.

below is the code needed to be added to Rtt_IPhoneWebViewObject.mm at approx line 133

WKWebViewConfiguration *theConfiguration = [[WKWebViewConfiguration alloc] init];
    
[theConfiguration.preferences  setValue:@YES forKey:@"allowFileAccessFromFileURLs"]; 
// needed to run web page from documents directory

[theConfiguration.preferences  setValue:@YES forKey:@"OfflineApplicationCacheIsEnabled"]; 
// needed to run web page from documents directory

// alternative initialization for web view
fWebView = [[WKWebView alloc] initWithFrame:webViewRect configuration:theConfiguration]; 


[TOPIC: post.html]
#2

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 26,622 posts
  • Enterprise

What version of Corona are you using? I thought we fixed this.

 

Rob



[TOPIC: post.html]
#3

cublah

[GLOBAL: userInfoPane.html]
cublah
  • Contributor

  • 393 posts
  • Corona SDK

2019.3562

 

if the source code is correct on github, then WKWebview isn’t configured for local files



[TOPIC: post.html]
#4

cublah

[GLOBAL: userInfoPane.html]
cublah
  • Contributor

  • 393 posts
  • Corona SDK

I don’t see where this was even mentioned or fixed, uiwebview will load local files but you transitioned to WKWebview on the 22nd nov and you have to handle that differently, this is something I’ve dealt with a lot in native iOS. 



[TOPIC: post.html]
#5

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 26,622 posts
  • Enterprise

If you're comfortable, you could pull down the source code, make the change, and after you test it, make a pull request to send your changes back up stream.

 

These are the kinds of things that the community can do to really help!

 

Rob



[TOPIC: post.html]
#6

cublah

[GLOBAL: userInfoPane.html]
cublah
  • Contributor

  • 393 posts
  • Corona SDK

Unfortunately I’m not a big github user, we use Perforce for our version control, although I could give it a go I’m sure, but if somebody wants to help then I know what the change has to be



[TOPIC: post.html]
#7

Studycat2

[GLOBAL: userInfoPane.html]
Studycat2
  • Enthusiast

  • 92 posts
  • Corona SDK

This is a breaking change for us - we need local HTML files as we make extensive use of them to display user-facing text from within our app.  Currently, we're using Corona build 3552 as it's the last version supporting UIWebView. However, there are important fixes ahead of this build (IAP stuff for example). 

 

Looks like it's a trivial change to allow local HTML files in WKWebView.  Can engineering prioritize this?

 

+1!

 

Thanks.



[TOPIC: post.html]
#8

pixec

[GLOBAL: userInfoPane.html]
pixec
  • Contributor

  • 170 posts
  • Corona SDK

Nah, they wont prioritize it. There are many more important things to do first.

[TOPIC: post.html]
#9

Studycat2

[GLOBAL: userInfoPane.html]
Studycat2
  • Enthusiast

  • 92 posts
  • Corona SDK

Fair enough. What's a solution in the interim? Presumably this is fixable with a plugin that wraps a WXWebView with the configuration in cublah's original post? 



[TOPIC: post.html]
#10

cublah

[GLOBAL: userInfoPane.html]
cublah
  • Contributor

  • 393 posts
  • Corona SDK

If someone can go through the process of what Rob suggested, the code posted above will work



[TOPIC: post.html]
#11

cublah

[GLOBAL: userInfoPane.html]
cublah
  • Contributor

  • 393 posts
  • Corona SDK

This is where the file is

 

https://github.com/coronalabs/corona/blob/master/platform/iphone/Rtt_IPhoneWebViewObject.mm



[TOPIC: post.html]
#12

cublah

[GLOBAL: userInfoPane.html]
cublah
  • Contributor

  • 393 posts
  • Corona SDK

You actually only need to add 3 lines

WKWebViewConfiguration *theConfiguration = [[WKWebViewConfiguration alloc] init];
    
[theConfiguration.preferences  setValue:@YES forKey:@"allowFileAccessFromFileURLs"]; 
// needed to run web page from documents directory

// alternative initialization for web view
fWebView = [[WKWebView alloc] initWithFrame:webViewRect configuration:theConfiguration]; 

Just replace line 134 with those 3 lines and it’s done



[TOPIC: post.html]
#13

XeduR @Spyric

[GLOBAL: userInfoPane.html]
XeduR @Spyric
  • Corona Geek

  • 1,176 posts
  • Corona SDK

If that's really all it takes, why not make a pull request?



[TOPIC: post.html]
#14

cublah

[GLOBAL: userInfoPane.html]
cublah
  • Contributor

  • 393 posts
  • Corona SDK

As I said in a previous post git is not really something I know or use.



[TOPIC: post.html]
#15

cublah

[GLOBAL: userInfoPane.html]
cublah
  • Contributor

  • 393 posts
  • Corona SDK

Ok I seemed to have done a pull request, I guess somebody needs to review it and merge it with the master branch


  • XeduR @Spyric and Studycat2 like this

[TOPIC: post.html]
#16

Studycat2

[GLOBAL: userInfoPane.html]
Studycat2
  • Enthusiast

  • 92 posts
  • Corona SDK

https://github.com/coronalabs/corona/pull/36

 

Thanks for this cublah! 



[TOPIC: post.html]
#17

Studycat2

[GLOBAL: userInfoPane.html]
Studycat2
  • Enthusiast

  • 92 posts
  • Corona SDK

What's involved in getting this tested and into a new Corona daily build? Is this something I can help with? 



[TOPIC: post.html]
#18

Studycat2

[GLOBAL: userInfoPane.html]
Studycat2
  • Enthusiast

  • 92 posts
  • Corona SDK

I did some experiments with UIWebView (Corona 3552) vs WKWebView (3555).

 

I got some strange results loading a simple webpage CachesDirectory or ResourceDirectory. See here: https://imgur.com/a/CVCbLhY

 

UIWebView never fails to load, but WKWebView sometimes fails, depending upon iOS version.

 

I expect https://github.com/coronalabs/corona/pull/36 might fix some of these, but I don't know how to build Corona from source and try this myself. 

 

In a separate test, I managed to get my web pages loading in a WKWebView, but only from ResourceDirectory, not CachesDirectory. CachesDirectory seems to be off-limits. This was with a much more complicate web page, with require.js, images, handbrake templates and other stuff - don't know if this affects things, will need to test more. 

kernel sandbox deny(1) file-issue-extension target:/ class:com.apple.app-sandbox.read


[TOPIC: post.html]
#19

cublah

[GLOBAL: userInfoPane.html]
cublah
  • Contributor

  • 393 posts
  • Corona SDK

This fix enables you to load local files from the documents directory, now it’s possible Apple have fixed this the the the last couple of versions of iOS but I know putting this in works on all versions, I’ve been using this in projects for the last 4 years and without it you can not read local files from the documents directory in all versions of iOS. I’m trying to get the fix added.


[topic_controls]
[/topic_controls]