Reputation: 105
I can get RAM details using (NSProcessInfo.ProcessInfo.PhysicalMemory). But i want to get free internal device storage using Xamarin IOS.
Upvotes: 2
Views: 1222
Reputation: 16449
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!
Upvotes: 0
Reputation: 7189
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;
}
}
}
Upvotes: 4