我们编写了一个代码,使用xamarin.ios中的webclient从uri下载图像。当我们下载图像时,它不会显示在图库/照片应用程序中,也不会显示在iPhone的任何其他位置。这是我的下载代码:
public void DownloadFiles()
{
try
{
var webClient = new WebClient();
webClient.DownloadDataCompleted += (s, e) => {
var bytes = e.Result;
string documentsPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
string localFilename = "downloaded.png";
string localPath = Path.Combine(documentsPath, localFilename);
Console.WriteLine("localPath:" + localPath);
File.WriteAllBytes(localPath, bytes);
// IMPORTANT: this is a background thread, so any interaction with
// UI controls must be done via the MainThread
InvokeOnMainThread(() => {
// imageView.Image = UIImage.FromFile(localPath);
UIAlertView alert = new UIAlertView()
{
Title = "alert title",
Message = "Download successfully"
};
alert.AddButton("OK");
alert.AddButton("Cancel");
alert.Show();
});
};
var url = new Uri("https://www.xamarin.com/content/images/pages/branding/assets/xamagon.png");
webClient.DownloadDataAsync(url);
}
catch(Exception e)
{
throw e;
}
}
Environment.GetFolderPath(Environment.SpecialFolder.Personal);
如何找到这条路?
我们在info.plist中添加了这些权限来解决此问题。 “隐私 - 照片库添加使用说明”和“隐私 - 照片库使用说明”