I can get RAM details using (NSProcessInfo.ProcessInfo.PhysicalMemory). But i want to get free internal device storage using Xamarin IOS.
Asked
Active
Viewed 1,169 times
2
-
What have you tried so far? – FreakyAli Sep 27 '18 at 06:51
-
I haven't tried.. all the code i am getting either for SWIFT or Objective C. I am using xamarin ios (C#). So i need code related to that. – Esrath Muqayyar Sep 27 '18 at 07:12
-
Did you try to convert the objective-c code to c#? – FreakyAli Sep 27 '18 at 07:15
-
i am new to Objective -C and C#. I dont have much knowledge on that. How to do that? – Esrath Muqayyar Sep 27 '18 at 07:16
-
https://stackoverflow.com/questions/5712527/how-to-detect-total-available-free-disk-space-on-the-iphone-ipad-device – Esrath Muqayyar Sep 27 '18 at 07:20
-
this is the code i got it from google. But it using Objective -C – Esrath Muqayyar Sep 27 '18 at 07:20
-
Okay let me try to convert it for you – FreakyAli Sep 27 '18 at 07:45
-
@EsrathMuqayyar Do you have any cache memory issue while implementing this ? I am having [this issue](https://stackoverflow.com/questions/63400844/get-ios-internal-storage-memory-information-xamarin-forms-ios#). I tried following answer code as well, but it is not helpful. Please check comments in my question. – Viral Narshana Aug 14 '20 at 19:16
2 Answers
4
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
- 7,035
- 1
- 26
- 45
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
- 13,349
- 3
- 23
- 63