Corona SDK:network.request无法在Android上运行



此代码在iOS上完美工作。

当我在SGSII Android手机上运行相同的线路时,根本没有任何进展。文本laddar...只是无限循环。

我已添加

"android.permission.INTERNET",

到我的build.settings文件。

这是我的代码:

local function fetchDataFromURL()

    local loadingText = display.newText("no text", 0,0,"Sintony", 40)
    loadingText.text = "Laddar stipendier..."
    loadingText:setReferencePoint(display.CenterLeftReferencePoint)
    loadingText.x = mainBox.x - loadingText.width/2
    loadingText.y = mainBox.y

    local function updateLoadingText()
        if (loadingText.text == "Laddar stipendier") then loadingText.text = "Laddar stipendier."  
        elseif (loadingText.text == "Laddar stipendier.") then loadingText.text = "Laddar stipendier.."   
        elseif (loadingText.text == "Laddar stipendier..") then loadingText.text = "Laddar stipendier..." 
        elseif (loadingText.text == "Laddar stipendier...") then loadingText.text = "Laddar stipendier" 
        end 
        loadingText:setReferencePoint(display.CenterLeftReferencePoint)
        loadingText.x = 134
    end
    local loadingTimer = timer.performWithDelay(500, updateLoadingText, 0)
    local function compare(a,b)
        return a.title < b.title
    end

    local function infoFetch(event)
            -- perform basic error handling
            if ( event.isError ) then
                print( "Network error!")
            else
            local data = json.decode(event.response)
            scholarshipTable = data.scholarships
            for key, value in pairs(scholarshipTable) do
                table.insert(namesOfScholarship,{title = value.title, id = value.id})
            end
            table.sort(namesOfScholarship, compare)
            timer.cancel(loadingTimer)
            loadingText:removeSelf()
            loadingText = nil
            createTableView()
            return true
            end
        end
      network.request( dataURL, "GET", infoFetch )
end

我看不出这个代码有什么问题,而且我确信它在我的android设备上不起作用。

如有任何帮助,我们将不胜感激。

更新到最新版本解决了我的问题

我看不出你的代码有什么问题

我认为问题是你的android设备,有时设备的互联网连接是的问题

您可以在请求时添加超时

local params = {}
params.timeout = 3 --in seconds
network.request( dataURL, "GET", infoFetch , params)

因此,如果在3秒内未加载,它将返回event.isError

最新更新