UIWebView - Javascript stop to respond

Hi everyone,


I have a complete application created with HTML5+JS and I use "Bridge commands" to call some C functions.

Everything works fine.


But I have a stupid problem sometimes when the device is locked and the application still for a long time in background on the moment that I unlock the device it returns to the application as expected but the events ( javascript ) not respond anymore.


So I need to finish the application and start again from the scratch and everything starts to work again.


Temporary I made a procedure to check the state and when I unlock the device, I force the page to reload.

It works, but if possible I would like to use another way.

Someone has the same issue? some tips?


Thanks

Replies

Is there a reason you're not using WKWebView instead of the long since deprecated uiwebview? We've been waiting for UIWebView to be officially deprecated since iOS 8."

KMT wrote:

Is there a reason you're not using

WKWebView
instead of the long since deprecated
UIWebView
?

Hmmm,

UIWebView
is only officially deprecated in the iOS 10.12 beta SDK, which hasn’t yet shipped, so labelling it as “long since deprecated” seems a bit rough.

lailton wrote:

I have a complete application created with HTML5+JS and I use "Bridge commands" to call some C functions. …

But I have a stupid problem sometimes when the device is locked and the application still for a long time in background on the moment that I unlock the device it returns to the application as expected but the events ( javascript) not respond anymore.

I’m not familiar with these “Bridge commands” but I suspect they’re using some sort of communication channel that gets broken when you move into the background. A classic example of this would be a TCP connection, where socket resource reclaim can tear the connection if you get suspended (see Technote 2277 Networking and Multitasking).

Your best option here is, as KMT suggested, to move on to

WKWebView
. It has much nicer native integration features, including
WKScriptMessage
, a very nice mechanism to message native code from JavaScript.

Oh, and it’s not deprecated (-:

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Yes, I should have said "we've been waiting for UIWebView to be officially deprecated since iOS 8."


Glad to hear it's final w/iOS 10.12, thanks 😉


Ken

Thanks for reply.
Yes, It make sense for me.