network.download don't work in iOS device

Hello,

This code works fine in simulator and Android devices, but doesn’t works in iPhone.

This is the same code that you can read in documentation about network.download. 

iPhone runs iOS 10.2 and I compiled the code with Xcode 8.1 in my MacBook.

 Do I need to activate any iOS extension? What is the problem?

local function networkListener( event ) if ( event.isError ) then print( "Network error - download failed: ", event.response ) elseif ( event.phase == "began" ) then print( "Progress Phase: began" ) elseif ( event.phase == "ended" ) then 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 local params = {} params.progress = true network.download( "http://docs.coronalabs.com/images/simulator/image-mask-base2.png", "GET", networkListener, params, "helloCopy.png", system.TemporaryDirectory )

In my project I used network.request() but I have the same problem too. iPhone returns Network error but works fine in Android devices and simulator.

Thanks…

You are running into a problem known as ATS App Transport Security. Apple starting with iOS 9 doesn’t allow access to http:// only https:// unless you instruct your app to specifically allow http:// to work.

See:

https://docs.coronalabs.com/guide/hardware/appleATS/index.html

Rob

Thanks for the quick reply. I did not see that article when I was looking at possible causes of the problem. Thanks Rob

Thanks for the quick reply. I did not see that article when I was looking at possible causes of the problem. Thanks Rob

You are running into a problem known as ATS App Transport Security. Apple starting with iOS 9 doesn’t allow access to http:// only https:// unless you instruct your app to specifically allow http:// to work.

See:

https://docs.coronalabs.com/guide/hardware/appleATS/index.html

Rob

Thanks for the quick reply. I did not see that article when I was looking at possible causes of the problem. Thanks Rob

Thanks for the quick reply. I did not see that article when I was looking at possible causes of the problem. Thanks Rob