Moni Bhattacharya
Moni Bhattacharya

Reputation: 133

Where is the ios LocalStorage when using PCLStorage for Xamarin forms?

I am using PCLStorage to store image in localStorage and access them via path returned.

Its working fine but the problem is, whenever I again start debugging the application, images are not accessible.

Where actually it stores images in Local Storage? Is it not permanent location? I want to store images in fileSystem and related data and image path in sqlite. Its an offline application so need to store this data permanently.

Any suggestions for this would be helpful.

Thanks

Upvotes: 1

Views: 795

Answers (2)

Moni Bhattacharya
Moni Bhattacharya

Reputation: 133

I got the answer for this question on Xamarin Forum so just updating the link here so it can help others.

https://forums.xamarin.com/discussion/comment/217282/#Comment_217282

As explained here that everytime we redeploy app the core path changes thats why on redeploying I was not able to find images on the path where I saved it. So now I am only saving the partial path like the folderName\the image name and rest of the core path I am finding on runtime.

This solved my problem.

Upvotes: -1

Ziyad Godil
Ziyad Godil

Reputation: 2680

Try below steps.

The interface is fairly simple because we're really only interested in passing the byte array and a filename when we save the image to disk.

public interface IPicture
{
    void SavePictureToDisk (string filename, byte[] imageData);
}

DependencyService will delegate image saving to the appropriate class. The usage for the DependencyService is:

DependencyService.Get<IPicture>().SavePictureToDisk("ImageName", GetByteArray());

Create Classes in Platform-Specific Projects

iOS Project

[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());
                }
            });
        }
    }
}

Upvotes: 1

Related Questions