0

I am working on a cordova ios (6.1.0) project and i want to implement a native WKURLSchemeHandler to intercept the custom scheme handling to solve my cors problems.

In detail I want to do something like: https://medium.com/@kumarreddy_b/custom-scheme-handling-in-uiwebview-wkwebview-bbeb2f3f6cc1

Till iOS 11, we do not have any system APIs to intercept events from WKWebView.In iOS 11 we got a new API called WKURLSchemeHandler for WKWebView to make our life simpler.

It means that if you want to handle some request on your own, then just define the custom scheme and set it to the WKWebViewConfiguration.

My custom scheme is app://myapp but i need to implement a WKURLSchemeHandler and register it to WKWebViewConfiguration.

Is there any way to implement native ios code on cordova?

user2048767
  • 115
  • 8

1 Answers1

2

You don't need to implement the SchemeHandler, its already in cordova-ios. Just put this scheme in your config.xml:

<platform name="ios">
  <preference name="scheme" value="app" />
  <preference name="hostname" value="localhost" />
  ....
</platform>

(and you might need to also set the iosExtraFilesystems and iosPersistentFileLocations prefs)

and in your JS code get the actual URL from WkWebKit, like for e.g. cordova.file.DataDirectory :

url = window.WkWebView.convertFilePath( cordova.file.dataDirectory ) + subPath;
window.open( url );
weHe
  • 306
  • 2
  • 5
  • This should be the accepted answer, I could use my code like regular accept with a simple addition of `if(window.WkWebView && window.WkWebView.convertFilePath) file = window.WkWebView.convertFilePath(file);` for image src. Works – DdD Oct 23 '20 at 02:12