05 March 2013
Networking 2.0
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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
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 ) |
Joe
Posted at 12:32h, 06 MarchGreat news, especially viewing bytes transferred.
sq2
Posted at 15:57h, 06 MarchIs event.bytesTransferred actually progress though? Does it work in the simulator? My quick tests suggest this isn’t the case.
Mustafa
Posted at 05:08h, 07 MarchGreat updates, just on time!
Perry
Posted at 13:37h, 08 MarchOne 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.
Bryan
Posted at 12:12h, 18 MarchThanks 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.
sq2
Posted at 14:57h, 21 MarchIs this in stable builds yet?
Nevin Flanagan
Posted at 22:23h, 23 MarchApparently, event.response is still a string when the call did not specify a file to store the transfer in.
Paulo
Posted at 15:46h, 15 AprilIs 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).