Xamarin.Form中的iOS路径以保存数据

问题描述

我想将数据保存在一个csv文件中,并且收到错误消息,指出路径不存在。有谁知道正确的路径?我已经在Internet上搜索并使用了不同的路径,但仍然无法正常工作。

解决方法

为了获得在iOS上保存文件的路径,我使用了类似的方法

            string photosPath = Environment.GetFolderPath( Environment.SpecialFolder.MyDocuments ) + "/Photos";
            IFileSystem fileSystem = FileSystem.Current;
            IFolder rootFolder = fileSystem.LocalStorage;
            IFolder photosFolder = rootFolder.CreateFolderAsync( photosPath,CreationCollisionOption.ReplaceExisting ).Result;
            ImageRepository.ImagePath = photosPath;

在iOS项目中添加它。

将路径保存在另一个类实例中,以便在任何地方轻松访问。

public class ImageRepository
    {
        public static string ImagePath { get; set; }
    }

ImageRepository.ImagePath用作您要保存文件的所有位置的路径。