Networking 2.0

CoronaOnly_med
Share on Facebook0Share on Google+2Tweet about this on TwitterShare on LinkedIn0

Starting with build 2013.1043, on iOS, Android, Mac and Windows, we are rolling out new functionality within our network api. Network functions like download, request have been enhanced with new functionality. Check out our daily API docs under network and events under networkRequest here, to see how to do things like upload text files in a single call, view bytes transferred and more…

Also, please note that there are a few new functional changes that aren’t backwards compatible. As you can see in the code example below, event responses are now tables which include fileName and baseDirectory. Be careful to ensure that you treat event.response as a table now instead of a string

Here is a simple example of how to use the new event.response table information.

local function networkListener( event )
        if ( event.isError ) then
                print( "Network error - download failed" )
        elseif ( event.phase == "ended" )
                print( "displaying response image file" )
                myImage = display.newImage( event.response.filename, event.response.baseDirectory, 60, 40 )
                myImage.alpha = 0
                transition.to( myImage, { alpha = 1.0 } )
        end
end
 
network.download(
        "http://developer.anscamobile.com/demo/hello.png",
        "GET",
        networkListener,
        "helloCopy.png",
        system.TemporaryDirectory
        )
Share on Facebook0Share on Google+2Tweet about this on TwitterShare on LinkedIn0
tom

This entry has 8 replies

  1. Joe says:

    Great news, especially viewing bytes transferred.

    • sq2 says:

      Is event.bytesTransferred actually progress though? Does it work in the simulator? My quick tests suggest this isn’t the case.

  2. Mustafa says:

    Great updates, just on time!

  3. Perry says:

    One known bug at the moment (daily build 2013.1043) is that network error messages are not showing in Windows XP. We’re looking into it.

  4. Bryan says:

    Thanks for the comments! It’s worth noting that we have extended the message support under Windows XP and we have resolved several small behavioral differences on iOS and Android in the latest daily build.

  5. sq2 says:

    Is this in stable builds yet?

  6. Apparently, event.response is still a string when the call did not specify a file to store the transfer in.

  7. Paulo says:

    Is it compatible with older versions of Android?
    I have tested successfully with Kindle (Android 2.3.4), but it fails with Android 2.3.5 (return status -1).

Leave a reply

You may use these HTML tags and attributes: <a href="" title="" rel=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>