network.download( ) error

Corona Simulator worked but no iOS Device (or Xcode Simulator)

– test code

local function networkListener( event )
if event.isError then
print(“error!”)
elseif event.phase == “ended” then
local img = display.newImage( event.response.filename, event.response.baseDirectory, display.contentCenterX, display.contentCenterY )
end
end

local url = "http://static-cdn.jtvnw.net/ttv-static/404_preview-640x360.jpg"
network.download( url, “GET”, networkListener, “test.jpg”, system.DocumentsDirectory )

What does it do on device? What does it respond?

Only thing I can think is the request is being blocked by Apple Transport Security.

  1. Open build.settings

  2. Go to iphone > plist

  3. Add this code to allow requests to and from static-cdm.jtvnw.net

    iphone = { plist = { NSAppTransportSecurity = { NSExceptionDomains = { [“static-cdm.jtvnw.net”] = { NSIncludesSubdomains = true, NSThirdPartyExceptionAllowsInsecureHTTPLoads = true, NSTemporaryExceptionMinimumTLSVersion = “1.0”, NSTemporaryExceptionRequiresForwardSecrecy = false, NSAllowsArbitraryLoads = true, }, }, }, }

Good luck!

Thank you for replying so promptly.

 

But it is still a problem.

 

please see the attached file (Test base: iOS device or Xcode simulator)

Hi Kim,

My mistake, change this line

["static-cdm.jtvnw.net"]

to

["jtvnw.net"]

I tested it on my iPhone 6 and it works as expected.

Reason: static.cdm is a subdomain of jtvnw.net, so strip any future url down, api.parse.com should be parse.com, media02.giphy.com/1234.gif should be giphy.com.

Have a good one, good luck on your project.

What does it do on device? What does it respond?

Only thing I can think is the request is being blocked by Apple Transport Security.

  1. Open build.settings

  2. Go to iphone > plist

  3. Add this code to allow requests to and from static-cdm.jtvnw.net

    iphone = { plist = { NSAppTransportSecurity = { NSExceptionDomains = { [“static-cdm.jtvnw.net”] = { NSIncludesSubdomains = true, NSThirdPartyExceptionAllowsInsecureHTTPLoads = true, NSTemporaryExceptionMinimumTLSVersion = “1.0”, NSTemporaryExceptionRequiresForwardSecrecy = false, NSAllowsArbitraryLoads = true, }, }, }, }

Good luck!

Thank you for replying so promptly.

 

But it is still a problem.

 

please see the attached file (Test base: iOS device or Xcode simulator)

Hi Kim,

My mistake, change this line

["static-cdm.jtvnw.net"]

to

["jtvnw.net"]

I tested it on my iPhone 6 and it works as expected.

Reason: static.cdm is a subdomain of jtvnw.net, so strip any future url down, api.parse.com should be parse.com, media02.giphy.com/1234.gif should be giphy.com.

Have a good one, good luck on your project.