Hello folks,
The native.newWebView’s URLRequest event listener does not work properly on iOS devices. It works fine in the simulator, but not so well when deployed to an actual iOS device (confirmed using 3GS and iPad 2).
Code to replicate the behavior on a device is as follows and available for download at :
local txt1, txt2, webView local function webListener( event ) txt1.text = "Event URL: " .. event.url txt1:setReferencePoint( display.TopLeftReferencePoint ) txt1.x = 150 txt2.text = "Event TYPE: " .. event.type txt2:setReferencePoint( display.TopLeftReferencePoint ) txt2.x = 150 end txt1 = display.newText("Event URL:", 50, 90, native.systemFont, 30 ) txt2 = display.newText("Event TYPE:", 50, 130, native.systemFont, 30 ) webView = native.newWebView( 50, 280, 680, 680 ) webView:request( "http://www.coronalabs.com/" ) webView:addEventListener( "urlRequest", webListener )
The ’ loaded’ event.type (as described in http://docs.coronalabs.com/api/event/urlRequest/type.html) only gets triggered once! Unfortunately, that particular event.type never gets triggered again; all subsequent page requests don’t report the ’ loaded’ event. For example, if one were to deploy the above code to an iOS device, the ’ loaded’ event.type gets passed to the listener once www.coronalabs.com has successfully loaded into the webview…however, all other pages that are accessed from then on (e.g clicking on the “Corona”, “Community”, “Resources”, “Blog” hyperlinks) ’ loaded’ event.type never gets passed to the event listener.
The above behavior only occurs on iOS devices. It works fine in the Corona simulator (mac version) and all event.types work as one would expect; every time the webview completes loading a new page, it passes ’ loaded’ to the listener as one would expect.
I was wondering if there is a work around for this or if there is a “fix” for it in the works. Perhaps there is another way to do this? My big picture idea is to use the “link” event.type and “loaded” event.type to help determine when to begin / stop the spinner widget for providing feedback to the enduser that a page is currently loading.
Regards