Pass data from ios native to Ionic web view


#1

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)


#2

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


#3

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.


#4

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


#5

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


#6
(<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