Search Unity

  1. Full schedule for #UniteBerlin is now available! Featuring talks on our roadmap, hands-on labs and much more! Check it out!
    Dismiss Notice
  2. Unity 2018.1 has arrived! Read about it here
    Dismiss Notice
  3. Scriptable Render Pipeline improvements, Texture Mipmap Streaming, and more! Check out what we have in store for you in the 2018.2 Beta.
    Dismiss Notice
  4. ARCore is out of developer preview! Read about it here.
    Dismiss Notice
  5. Magic Leap’s Lumin SDK Technical Preview for Unity lets you get started creating content for Magic Leap One™. Find more information on our blog!
    Dismiss Notice
  6. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Display Google static map will get NSURLConnection finished with error and get blank image

Discussion in 'iOS and tvOS' started by yayapeter, May 16, 2018.

  1. yayapeter

    yayapeter

    Joined:
    Jun 24, 2014
    Posts:
    19
    I want to show google static map in the ios device.
    I have a url and getHttpImage function below , it's working in the web browser,ios Unity Editor and android device , but it will show blank and get an error below in the ios device.

    Error:

    "You are using download over http. Currently Unity adds NSAllowsArbitraryLoads to Info.plist to simplify transition, but it will be removed soon. Please consider updating to https.
    NSURLConnection finished with error - code -1002
    Error while downloading: Unknown Error

    "

    URL:
    https://maps.google.com/maps/api/st...pg9Xv-tpx47puQlvBCI6deN|33.282798,-111.856303




    Unity code snippet
    Code (CSharp):
    1.     IEnumerator getHttpImage (Image image,string url,int width,int height) {
    2.  
    3.         //A URL where the image is stored
    4.         //Call the WWW class constructor
    5.         WWW imageURLWWW = new WWW(url);
    6.  
    7.         //Wait for the download
    8.         yield return imageURLWWW;      
    9.  
    10.         //Simple check to see if there's indeed a texture available
    11.         if(imageURLWWW.texture != null) {
    12.  
    13.             if(getResponseCode(imageURLWWW) == 403){
    14.                 //do it again
    15.                 setHttpImage(image,url,width,height);
    16.                 yield return null;
    17.             }
    18.  
    19.            
    20.             //Create a new sprite using the Texture2D from the url.
    21.             //Note that the 400 parameter is the width and height.
    22.             //Adjust accordingly
    23.             Sprite sprite = Sprite.Create(imageURLWWW.texture, new Rect(0, 0, width, height), Vector2.zero);
    24.  
    25.             //Assign the sprite to the Image Component
    26.             image.sprite = sprite;
    27.             image.SetNativeSize ();
    28.  
    29.         }
    30.  
    31.         yield return null;
    32.     }

    XCode Info.plist content already include below:

    <key>NSAppTransportSecurity</key>

    <dict>

    <key>NSAllowsArbitraryLoads</key>

    <true />

    <key>NSExceptionDomains</key>

    <dict>

    <key>drive.google.com</key>

    <dict>

    <key>NSExceptionRequiresForwardSecrecy</key>

    <false />

    <key>NSIncludesSubdomains</key>

    <true />

    </dict>

    <key>maps.google.com</key>

    <dict>

    <key>NSExceptionRequiresForwardSecrecy</key>

    <false />

    <key>NSIncludesSubdomains</key>

    <true />

    </dict>

    </dict>

    </dict>


    How can I fix it?