IOS UiWebView / Api page visibility: event "pageshow" does not fire

I am trying to use Api Page Visibility to determine when web content is displayed on iOS. I have a simple JS:

window.addEventListener("pageshow", function(){ alert("page shown"); }, false); 

A warning is triggered, as expected, in a mobile safari when the tab is activated, or when the safari is minimized and then re-displayed.

However, if I host web content in a UiWebView, the event does not fire. Has anyone else encountered this problem? If so, then do you need to work for this?

Thanks...

+6
source share
2 answers

Dose UIWebView does not support this event, however you can see how to trigger the event yourself from the application

What do you call a JavaScript function from Objective-C Goal C send data to phonegap and call javascript function

Then you just use the code above to notify the web browser when you are processing an application that is running or restarted from suspension

Goal C: How to check if the application is really active (for example, the user uses it)? should help with this

+1
source

I completely agree with the answer above. Even though the pageVisibilityChange event cannot be fired in UIWebview. you can still detect it by your own code, and then notify JS using JS-bridge technology or JS-binding.

There is another method to achieve this setInterval function. You can initialize the variable for the current timestamp at the beginning of the application’s lunch, and then increase this variable by one second in each interval callback function. you need to compare the current timestamp with this variable, if they have a difference of one second, this means that the setInterval callback has been blocked! This way you can indicate that the page has gone out in the least number of seconds of servlets.

0
source

All Articles