Display image from remote location

Hi good evening,

 

I’m trying to load a remote image via “display.loadRemoteImage”, it only works on simulator, it doesn’t work mobile phone. Is there a setup I need to do to make it work I already enable the write external strorage and internet permision.

 

local function networkListener( event )

        if ( event.isError ) then

                print ( “Network error - download failed” )

        else

               anchor(event.target)

               event.target.x = 0

               event.target.y = 0

        end

end

local img_map = display.loadRemoteImage( “http://maps.googleapis.com/maps/api/staticmap?center=13.6217, 123.21781&zoom=16&size=120x100”, “GET”, networkListener, “map_thumbnail.png”, system.DocumentsDirectory, 0, 0 )

Thanks,

What device? If it’s iOS running iOS 9 or later, you can’t access http:// addresses without adding some exceptions to your build.settings. It’s called App Transport Security (ATS). Basically Apple is forcing people to use https:// addresses. It’s 2016 and there is no excuse for a website to not be encrypted (Apple’s thinking, but I happen to agree). In fact iOS 10 will do away with the exceptions with out written approval from Apple. You can read about it here:

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

But in your case, try changing the URL from http:// to https:// and see if that changes things. All Google endpoints should be https: capable now.

And if any one wants to argue about “It costs to much” or “it too difficult” to get an SSL certificate, I would suggest checking out:

https://letsencrypt.org/

Your hosting provider may support them already. Its like a trivial install process. For my host, I was presented a screen of my domain names and a check box. I checked the ones I wanted SSL on, hit the submit button and done.  For those sites running on my full server at Digital Ocean, I had to install a small script, ran it, listed my domains to set SSL up on and hit submit.

Rob

I’m using PC, the script works fine on emulator it displays the image, but when I publish it and try it on my android device it doesn’t display the image.

Any messages in your console log? (adb logcat)

On the corona simulator output or in my mobile device? In simulator it works fine, but when I run it on mobile it doesn’t display the image.

The device.

I am going to ball park it and say you need to make sure your internet permission on android.

I’m using android phone. I really didn’t know what happen but it’s working now.

Thanks for your reply,

What device? If it’s iOS running iOS 9 or later, you can’t access http:// addresses without adding some exceptions to your build.settings. It’s called App Transport Security (ATS). Basically Apple is forcing people to use https:// addresses. It’s 2016 and there is no excuse for a website to not be encrypted (Apple’s thinking, but I happen to agree). In fact iOS 10 will do away with the exceptions with out written approval from Apple. You can read about it here:

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

But in your case, try changing the URL from http:// to https:// and see if that changes things. All Google endpoints should be https: capable now.

And if any one wants to argue about “It costs to much” or “it too difficult” to get an SSL certificate, I would suggest checking out:

https://letsencrypt.org/

Your hosting provider may support them already. Its like a trivial install process. For my host, I was presented a screen of my domain names and a check box. I checked the ones I wanted SSL on, hit the submit button and done.  For those sites running on my full server at Digital Ocean, I had to install a small script, ran it, listed my domains to set SSL up on and hit submit.

Rob

I’m using PC, the script works fine on emulator it displays the image, but when I publish it and try it on my android device it doesn’t display the image.

Any messages in your console log? (adb logcat)

On the corona simulator output or in my mobile device? In simulator it works fine, but when I run it on mobile it doesn’t display the image.

The device.

I am going to ball park it and say you need to make sure your internet permission on android.

I’m using android phone. I really didn’t know what happen but it’s working now.

Thanks for your reply,