gree / unity-webview

zlib License
2.27k stars 687 forks source link

iOS Custom Callback not getting called sometimes #681

Open ReGaSLZR opened 3 years ago

ReGaSLZR commented 3 years ago

Hello, @KojiNakamaru -san. Thank you for your hard work.

My team implemented the custom Unity.call hooking for callbacks on the HTML side and on the Unity side which you prescribed here: https://github.com/gree/unity-webview/issues/563

My team also implemented the custom cb callback/delegate designation on webViewObject.Init()

It works perfectly on Android; the callback gets called and our logs are printed on LogCat. On iOS, the callback also works but... not all the time.

We've checked the HTML codes, if in case there were any discrepancies. Also checked our Unity codes, but we see nothing wrong.

Can I confirm with you: Is there something we can do for the iOS counterpart to work 100%? On Android, there's no problem.

KojiNakamaru commented 3 years ago

In the sample app, Unity.call() is defined in the ld: callback for iOS, thus it is not available initially.

https://github.com/gree/unity-webview/blob/a11f2c2dff17feb9ebbed5beb81721ca5d5db348/sample/Assets/Scripts/SampleWebView.cs#L66-L80

It won't work if you call it before it is defined. If you can control the html content, it is better to define it in <script> so that you can surely use it after the definition.

ReGaSLZR commented 3 years ago

Ah, then I wanna add the information that we also added the callback on ld before filing this ticket. Is there any other configuration we might have possibly missed for iOS?

KojiNakamaru commented 3 years ago

As I wrote, it might be the cause that you added the callback on ld: as in the sample app. If Unity.call() is invoked before ld: is called, it won't work. Therefore, if you can modify the html to add the definition of Unity.call() with <script> tag instead of defining it on ld:, such the timing issue won't happen.

ReGaSLZR commented 3 years ago

Good evening!

Therefore, if you can modify the html to add the definition of Unity.call() with Githubissues.

  • Githubissues is a development platform for aggregating issues.