native.showWebPopup Fails randomly with multiple redirects

I am using native.showWebPopup to show web sites in my app. However, some randomly fail.

Here is an example: I try to show “http://www.gtopp.org/data/current-tags.html”, and after two redirects, it poops out. Now, I’m skipping over -999 errors, so my code isn’t stopping at that point…simply no website appears!

Help!

------------------------------------------------- -- POPUP: popup web page ------------------------------------------------- local function popupWebpage(targetURL, color, bkgdAlpha, transitionTime, netrequired, noNetMsg) local testing = false local closing = false if (type(targetURL) == "table") then color = trim(targetURL[2]) bkgdAlpha = tonumber(targetURL[3]) transitionTime = tonumber(targetURL[4]) targetURL = trim(targetURL[1]) end --print ("FUNX:popupWebPage() : targetURL",targetURL) -------------------------- local function doPop(isReachable) --print ("doPop says, isReachable =", isReachable) if (isReachable) then local mainImage local pgroup = display.newGroup() anchor(pgroup, "Center") pgroup.x, pgroup.y = midscreenX, midscreenY color = color or "white" bkgdAlpha = bkgdAlpha or 0.95 transitionTime = transitionTime or 300 local function killme() if (pgroup ~= nil) then display.remove(pgroup) pgroup=nil --print "Killed it" else --print ("Tried to kill pGroup, but it was dead.") end end local function closeMe(event) if (not closing and pgroup ~= nil) then native.cancelWebPopup() transition.to (pgroup, {alpha=0, time=transitionTime, onComplete=killme} ) closing = true end return true end -- cover all rect, darken background local bkgdrect = display.newRect(0,0,screenW,screenH) pgroup:insert(bkgdrect) anchor(bkgdrect, "Center") bkgdrect:setFillColor( 55, 55, 55, 190 ) -- background graphic for popup local bkgd = display.newImage("\_ui/popup-"..color..".png", true) checkScale(bkgd) pgroup:insert (bkgd) anchor(bkgdrect, "Center") bkgd.alpha = bkgdAlpha local closeButton = widget.newButton { id = "close", defaultFile = "\_ui/button-cancel-round.png", overFile = "\_ui/button-cancel-round-over.png", onRelease = closeMe, } pgroup:insert(closeButton) anchor(closeButton, "TopRight") anchorZero(closeButton, "Center") closeButton.x = (bkgd.width/2) - closeButton.width/4 closeButton.y = -(bkgd.height/2) + closeButton.height/4 closeButton:toFront() pgroup.alpha = 0 -- Capture touch events and do nothing. pgroup:addEventListener( "touch", function() return true end ) local function showMyWebPopup() local function listener( event ) local shouldLoad = true if ( event.errorCode and event.errorCode ~= -999 ) then -- Error loading page print( "showMyWebPopup: Error: " .. tostring( event.errorMessage ) ) shouldLoad = false end return shouldLoad end -- web popup local x = (screenW - bkgd.width)/2 + (closeButton.width) local y = (screenH - bkgd.height)/2 + (closeButton.height) local w = bkgd.width - (2 \* closeButton.width) local h = bkgd.height - (2 \* closeButton.width) --print ("showWebMap: go to ",targetURL) --print (x, y, w, h, targetURL) local options = { hasBackground=true, urlRequest = listener, -- Only need this for local URLs --baseUrl=system.ResourceDirectory, } native.showWebPopup(x, y, w, h, targetURL, options ) end transitionTime = tonumber(transitionTime) transition.to (pgroup, {alpha=1, time=transitionTime, onComplete=showMyWebPopup } ) else noNetMsg = noNetMsg or "No Internet" tellUser(noNetMsg .. ":" .. targetURL) end end -- callback function -------------------------- -- Do we have network? -- Don't test with our URL, since it might have authentication in it, -- e.g. human:password@myurl.com --local testurl = targetURL local testurl = "https://google.com" if (substring(testurl, 1, 4) == "http") then testurl = testurl:gsub("^https?://", "") end -- strip subfolders b/c of iOS bug testurl = gsub(testurl, "/.\*", "") -- If this is HTTP, warn developer that he should use HTTPS if (substring(targetURL, 1, 5) ~= "https") then print ("WARNING: funx.popupWebPage(): You are using http:// when you should use https:// because Apple's ATS does not like insecure connections: ",targetURL) end canConnectWithServer(testurl, false, doPop, testing) end

RESULTS:

showWebPopup: http://www.gtopp.org/data/current-tags.html ======== popupWebpage:listener [table] { [str] url="http://oceanview.pfeg.noaa.gov/GTOPP/all/gtopp2.html?w=960&h=600&species=all&lat=45&lon=-145&z=3&p=no&sstmin=5&sstmax=14&showsst=no&days=30" } ======== event.errorCode nil popupWebpage:listener [table] { [str] url="http://oceanview.pfeg.noaa.gov/GTOPP/all/gtopp2.html?w=960&h=600&species=all&lat=45&lon=-145&z=3&p=no&sstmin=5&sstmax=14&showsst=no&days=30&wmode=transparent" } ======== event.errorCode nil popupWebpage:listener [table] { [num] errorCode=-999 [str] url="http://oceanview.pfeg.noaa.gov/GTOPP/all/gtopp2.html?w=960&h=600&species=all&lat=45&lon=-145&z=3&p=no&sstmin=5&sstmax=14&showsst=no&days=30" [str] errorMessage="The operation couldn’t be completed. (NSURLErrorDomain error -999.)" } ======== event.errorCode -999

I found that simply using the newer, native.newWebView(), made the problem go away. It only took a few lines to make the change.

Glad you solved it.

I found that simply using the newer, native.newWebView(), made the problem go away. It only took a few lines to make the change.

Glad you solved it.