When the Webview call this, here is what it logs in xCode:
Then if we destroy the Webview, and recreate another after, this log appears one time, but Unity logs 2 callback instead of one. If we destroy again the WebView, the next instance will call 3 times the callback.
Any idea of why ?
PS: We are really destroying the object before creating the new one, we have logs in dealloc of our object and the logs are called. Everything seams fine on the Obj-C side, I think the problem is on Unity side but I can’t find what.
one potential pitfall is that UnitySendMessage will actually just queue the call. So you need to run player loop to actually make the call. I am not sure what you mean by “logging callback” etc, so that might be not the answer you are looking for - but it is good to know these details
Hi,
What I want to do is send a callback to a server when the page inside the webview is loaded.
To do it, I evaluate a javascript code that do something like Unity.call inside the JS of the page.
This function Unity.call basically create an iframe with a src prefixed with “unity:”
This way I can track in Obj-C when JS calls this function with shouldStartLoadWithRequest function.
Then if this function detects the prefix unity: , it calls a Unity function with UnitySendMessage.
With NSLog I can confirm that shouldStartLoadWithRequest is called 1 time.
But on the Unity side, my function is called as many time as the webview have been created before.
So if I open 2 webviews, that I destroy and after I create a new one, the function in Unity will be called 3 times but the function shouldStartLoadWithRequest in Obj-C is called one time.
Then I create a new webview and I do exactly the same.
When i will call the Unity.call function, this will debug this:
So maybe I do something wrong but I search for days the problem and couldn’t find it. Moreover when I debug the webview in Safari, there is only one declaration of the Unity.call function so I really think this is on the Unity side.
But when I do the exact same thing on Android, the function is called once…
(Except that I don’t have to do an iframe to call a function from JS to Java)