Xamarin.Forms.Image not picking up a remote image on iOS

ChaseFlorellChaseFlorell CAInsider, University mod

The following code works as expected on Android, but on iOS, the image doesn't appear.

var videoImage = new Image { Source = video.Pictures[0].Link, Aspect = Aspect.AspectFill };

Attached is a screenshot of the breakpoint. Is this a known issue? Is there an existing workaround?

There is no debug info to follow up with.

Answers

  • StephaneDelcroixStephaneDelcroix USInsider, Beta ✭✭✭✭

    Could you please provide the simplest possible repro case ? thx

  • ChaseFlorellChaseFlorell CAInsider, University mod

    I'm still trying to figure this out. I created a repro case, and copied the code across "exactly" and it worked fine.

    Now I'm back in my main project and I've created a basic page with nothing but a remote image on it, and it won't render.

    <?xml version="1.0" encoding="utf-8" ?>
    <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
                           xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                           x:Class="FutureState.AppCore.Pages.Delete">
      <Image Source="https://vsipprogram.com/content/upload/logo/Xamarin%20Inc..zpoh_xamarin-logo-hexagon-blue.png" WidthRequest="100" HeightRequest="100" />
    </ContentPage>
    

    Now I know that iOS isn't like Android, asking for permissions for something. Why would images work on a new project, but this one not? I'm so confused.

  • DiogoDiogo USMember

    Same problem and behaviour here. In a new project its all working... :/

  • ChaseFlorellChaseFlorell CAInsider, University mod

    Well, glad I'm not the only one. I thought I was going crazy.

  • StephaneDelcroixStephaneDelcroix USInsider, Beta ✭✭✭✭

    the UriImageSource does image caching. it might be possible that, due to a network issue, the cached image is invalid. The default cache duration is 24hours, but you can change it. you can also disable the caching totally, to help you figure your problem out.

  • ChaseFlorellChaseFlorell CAInsider, University mod
    edited July 2014

    It's definitely not the image cache. I tried loading up a random image into an <Image />, and it came up blank.

  • ChaseFlorellChaseFlorell CAInsider, University mod

    Another follow-up... I put the following on a page, the local image showed, and the remote one did NOT :S #puzzled.

    <Image Source="banner.png" />
    <Image Source="http://rasowe-psy.blog.pl/files/2014/05/puppy.png" />
    
  • CraigDunnCraigDunn USXamarin Team Xamurai

    Sorry... I can't repro, both:

    <Image Source="http://rasowe-psy.blog.pl/files/2014/05/puppy.png" />
    

    and

    <Image Source="https://vsipprogram.com/content/upload/logo/Xamarin Inc..zpoh_xamarin-logo-hexagon-blue.png" WidthRequest="100" HeightRequest="100" />
    

    work for me. Note that I added these elements to an existing Xaml project (didn't create a new one).

    Sorry but it's hard to know what the problem could be without a reliable repro case. I know it sounds crazy, but are these image URLs available on the device if you type them into the browser directly (ie Safari on iOS, outside of your app)? Also, anything else that's different in your environment - does it fail in both DEBUG and RELEASE builds?

  • ChaseFlorellChaseFlorell CAInsider, University mod
    edited July 2014

    @CraigDunn‌

    I know it sounds crazy, but are these image URLs available on the device if you type them into the browser directly (ie Safari on iOS, outside of your app)?

    yes I can see it in the browser.

    does it fail in both DEBUG and RELEASE builds?

    yes, it's failing for both.


    So I pushed my source and then pulled it down on my Mac, then built it, and the images appeared. I pushed any csproj changes back up, and pulled it back down into Visual Studio... and it fails.

    This appears to be something fishy with Xamarin for Visual Studio... maybe.

  • GlinttHSGlinttHS PTMember

    Hi,

    I'm experiencing the same behavior as Chase Florell. On mac it works fine and on Win+VS remote images are not downloaded/displayed.

  • CraigDunnCraigDunn USXamarin Team Xamurai

    I pushed any csproj changes

    could you do a 'diff' of the changes between the version running on Mac versus Visual Studio. It does sound very strange :-\

    @GlinttHS‌ what platforms are you testing on (iOS, Android|simulator, device)?

  • ChaseFlorellChaseFlorell CAInsider, University mod
    edited July 2014

    @CraigDunn I had a similar experience, except my VS builds don't show iOS remote images, but when I build in XS on Mac, they do show up.

    edit: oops, I ready @GlinttHS‌'s comment wrong. Yes my behaviour is exactly the same.

  • CraigDunnCraigDunn USXamarin Team Xamurai

    @ChaseFlorell‌ and there's no differences between the code, project, solution files? so weird (and hard to diagnose)...

  • ChaseFlorellChaseFlorell CAInsider, University mod
    edited July 2014

    no difference. Actually, I only develop in VS, so I

    • committed to source
    • brushed the dust off of my Mac
    • git clone my project in OS X
    • fire up X.S and load the freshly cloned solution
    • set iOS as startup
    • run
    • VOILA, images appear.
  • GlinttHSGlinttHS PTMember

    @CraigDunn we are testing on IOS simulator and device (same problem) and Android device (no problem). There are no differences between the projects. It's really hard to diagnose something like this...

  • JimBennettJimBennett GBXamarin Team, Insider, University, Developer Group Leader ✭✭✭✭

    I think I'm seeing the same problem - image loads fine in the browser but when I render it on an iOS app it's grey with just the first couple of lines visible. Looks like the image was cut off after the first few bytes.

  • LeandroLancelotiLeandroLanceloti BRMember ✭✭

    Same problem here... on simulator it works, on device no.

  • RenaudLaloireRenaudLaloire BEUniversity ✭✭

    Same problem as well. Image does not render on my device but in y simulator yes.

    Anyone with a solution?

    Thx

  • RenaudLaloireRenaudLaloire BEUniversity ✭✭

    Ok, I solved it disabling the cache:

    img.Source = new UriImageSource {CachingEnabled = false, Uri=new Uri("http://...")}

  • I just had a similar problem... It worked yesterday, I reverted to Stable channel from Alpha and it stopped working in Simulator iPhone 5S 8.1
    It didn't work for me in that simulator, but after I switched to device - it worked, and it was able to load images on a different simulator (iPhone 6) as well.
    Not sure what was the reason. Some logging to the Debug output would be appreciated from Image implementations....

  • JGoldbergerJGoldberger USMember, Forum Administrator, Xamarin Team, University Xamurai

    I filed a bug report about this issue here: https://bugzilla.xamarin.com/show_bug.cgi?id=35818

    Feel free to add any further relevant info to the bug report. I was only able to reproduce on iOS on my end. And even with caching disabled, the image still did not show occasionally.

  • MauricioRojasMauricioRojas USMember

    In my case the problem was because it is not supported loading images from https. I assume it is an issue with httpclient.
    Just changed to http and everything worked

  • +1

  • PabloBiagioliPabloBiagioli USMember ✭✭

    This is probably a result of Apple's new app transport security denying a non-HTTPS request. To work around this you need to modify your app's Info.plist file. You can either define an exception for that particular domain or disable ATS altogether.

    To disable ATS you need to add this code to your Info.plist

    <key>NSAppTransportSecurity</key>
    <dict>
        <key>NSAllowsArbitraryLoads</key>
        <true/>
    </dict>
    

    Hope this helps you. I ended up using a PlatformEffect to override the UriImageSource for an NSUrl.
    More info here: https://forums.xamarin.com/discussion/52090/uiimage-loadfromdata-not-working-on-ios-9

    Regards!

Sign In or Register to comment.