当Xamarin表单使用PCLStorage时,ios LocalStorage在哪里?
问题描述:
我正在使用PCLStorage将图像存储在localStorage中,并通过返回的路径访问它们。当Xamarin表单使用PCLStorage时,ios LocalStorage在哪里?
它的工作正常,但问题是,每当我再次开始调试应用程序,图像不可访问。
实际上它将图像存储在本地存储中?这是不是永久位置? 我想在sqlite中将图像存储在fileSystem以及相关数据和图像路径中。它是一个离线应用程序,因此需要永久存储这些数据。
对此的任何建议将有所帮助。
谢谢
答
我得到的答案对Xamarin论坛这个问题,所以才更新这里的链接,这样可以帮助其他人。
https://forums.xamarin.com/discussion/comment/217282/#Comment_217282
如这里解释说,每次我们重新部署应用程序的核心路径改变这就是为什么在重新部署我没能在那里我救了它的道路上查找图片。所以现在我只保存部分路径,如folderName \图像名称和我在运行时发现的核心路径的其余部分。
这解决了我的问题。
答
请尝试以下步骤。
该接口非常简单,因为我们真的只关心在将图像保存到磁盘时传递字节数组和文件名。
public interface IPicture
{
void SavePictureToDisk (string filename, byte[] imageData);
}
DependencyService将委托图像保存到相应的类。对于DependencyService用法是:
DependencyService.Get<IPicture>().SavePictureToDisk("ImageName", GetByteArray());
在特定平台的项目创建类
的iOS项目
[assembly: Xamarin.Forms.Dependency(typeof(Picture_iOS))]
namespace ImageSave.iOS
{
public class Picture_iOS: IPicture
{
public void SavePictureToDisk(string filename, byte[] imageData)
{
var MyImage = new UIImage(NSData.FromArray(imageData));
MyImage.SaveToPhotosAlbum((image, error) =>
{
//you can retrieve the saved UI Image as well if needed using
//var i = image as UIImage;
if(error != null)
{
Console.WriteLine(error.ToString());
}
});
}
}
}
感谢您的回复。我知道我们可以使用Dependency服务来做到这一点。但只想知道在这里解释的PCLStorage https://github.com/dsplaisted/PCLStorage。这对我来说工作得很好,但是我面临的唯一问题是我无法在重新调试应用程序时访问图像。否则,在杀死应用程序并重新启动设备中的应用程序工作正常。所以我想知道PCLStorage实际存储图像的位置? –