1

I can get RAM details using (NSProcessInfo.ProcessInfo.PhysicalMemory). But i want to get free internal device storage using Xamarin IOS.

2 Answers2

3

The method for getting the internal free space is this one:

  NSFileManager.DefaultManager.GetFileSystemAttributes (Environment.GetFolderPath (Environment.SpecialFolder.Personal)).FreeSize;

If you are using Xamarin.Forms, you can make a custom interface

namespace Your.Namespace.Interfaces
{
    public interface IStorageInterface
    {
        double GetFreeSpace(); //Not sure about the return type, try long, or double

    }
}

In your iOS Project:

[assembly: Xamarin.Forms.Dependency(typeof(Your.Namespace.iOS.StorageRenderer))]
namespace Your.Namespace.iOS
{
    public class StorageRenderer : IStorageInterface
    {
        public double GetFreeSpace()
        {
            return NSFileManager.DefaultManager.GetFileSystemAttributes (Environment.GetFolderPath (Environment.SpecialFolder.Personal)).FreeSize;
        }

    }
}
Bruno Caceiro
  • 6,179
  • 1
  • 19
  • 37
0

I have converted your code into Xamarin.iOS and it is as follows:

private ulong GetFreeDiskspace()
    {
        ulong totalSpace = 0;
        ulong totalFreeSpace = 0;
        NSError error = null;
        string[] paths = NSSearchPath.GetDirectories(NSSearchPathDirectory.UserDirectory, NSSearchPathDomain.All);
        var defManager = NSFileManager.DefaultManager;
        var dicAttributes = defManager.
            GetFileSystemAttributes(paths.First()
            , out error);
        totalSpace = dicAttributes.Size;
        totalFreeSpace = dicAttributes.FreeSize;
        return totalFreeSpace;
    } 

Good luck!

In case of queries revert!

FreakyAli
  • 9,662
  • 3
  • 16
  • 45