Pass data from ios native to Ionic web view

I’ve been stuck for 2 days now trying to figure out how to pass data from swift to the WKwebview that contains the ionic application(hybrid)

I know that in ios we can evaluate a js function thus running it.

Swift

webView.evaluateJavaScript("PassDataToJavascript()");

Javascript

build/main.js ==>l.prototype.PassDataToJavascript()


doesn't allow us to see the evaluate PassDataToJavascript()

How do you guys communicate between native and hybrid(webview)

Anyways to expose the js function in build/main.js to window object so we can call it from IOS?:joy:

So you are not containing your Ionic app in a common Cordova based app?
In general: Look at any of the Cordova plugins. Communicating between native and Ionic is exactly what they do.

1 Like

Thanks I was able to pass data with this method : (window).favList=[]; hopefully it will help anyone in the future!

Can you explain a bit more how exactly you used this please?

(<any>window).mydata;



my function()
{
//GOT SOME DATA someData

mydata = somedata;

}

then you can have access to mydata from the window object from chrome console or ios evaluate this window.mydata

Can you explain this please? I am not understand. (<any>window).mydata; is the Swift code? Where to use this?

Please open a new forum post. Commenting on a 4+ year old post is probably not going to be the best way to get help :grimacing: