Im using image in xamarinforms and im binding the source from remote uri, it works in android but when it comes to ios the image is not showing at all. Please someone help me regarding this.
0
votes
3 Answers
0
votes
0
votes
In ios if you are loading images from http then you have to add NSAppTransportSecurity in your info.plist file then it will work.
By default ios load images from secure url(start with https)
you can refer this How do I load an HTTP URL with App Transport Security enabled in iOS 9?
0
votes
If you are doing this in Code behind:
ImageSource.FromFile("ImageName.jpg") // from local source,
ImageSource.FromUri(new Uri(url)) // from remote source.
If you are trying to bind from XAML, you can use a converter and return the images;
<ContentView.Resources>
<ResourceDictionary>
<converters:ImageConverter x:Key="ImageConverter" />
</ResourceDictionary>
</ContentView.Resources>
<Image Grid.Row="1" Grid.Column="0" Source="{Binding YourObjectHere, Converter={StaticResource ImageConverter}}" />
In Converter class:
public class ImageConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value != null)
{
if (value is YourObject xxx)
{
var url = xxx.Images?["small"]; // This is custom code here, you build your url
return string.IsNullOrEmpty(url) ? ImageSource.FromFile("NoImage.jpg") : ImageSource.FromUri(new Uri(url));
}
}
return ImageSource.FromFile("NoImage.jpg");
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return null;
}
}
