获取ios内部存储内存信息xamarin forms ios [英] Get ios internal storage memory information xamarin forms ios
问题描述
我无法从 iPhone 设备获得实际的免费存储空间.我正在使用
正如上面所评论的,iOS 在缓存中保留了一些内存,我填充了设备的全部内存,因此设备中只剩下 300 MB 可用空间.当时我得到了准确的状态.因此,我建议是否有人致力于在问题区域中提及的功能尝试填充您的 ios 设备,然后进行测试.以下是我在两个平台上的最终代码.
安卓代码
public double GetRemainingInternalMemoryStorage(){//使用StatFSvar path = new StatFs(System.Environment.GetFolderPath(System.Environment.SpecialFolder.LocalApplicationData));long blockSize = path.BlockSizeLong;long avaliableBlocks = path.AvailableBlocksLong;double freeSpace = blockSize * avaliableBlocks;freeSpace = Math.Round(freeSpace/(1024 * 1024), 1);//将自由空间转换为 mb.Android 遵循二进制模式,因此除以 1024.返回空闲空间;}
iOS 代码
public double GetRemainingInternalMemoryStorage(){NSFileSystemAttributes applicationFolder = NSFileManager.DefaultManager.GetFileSystemAttributes(Environment.GetFolderPath(Environment.SpecialFolder.Personal));double freeSpace = applicationFolder.FreeSize;freeSpace = Math.Round(freeSpace/(1000 * 1000), 1);//将自由空间转换为 mb.iOS 遵循十进制模式,所以除以 1000返回空闲空间;}
I am not able to get actual free storage space from iPhone device. I am using this link to get storage space in xamarin forms ios. Following is my code from the link.
public double GetRemainingInternalMemoryStorage()
{
NSFileSystemAttributes applicationFolder = NSFileManager.DefaultManager.GetFileSystemAttributes(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData));
var freeSpace = applicationFolder.FreeSize;
var totalSpace = applicationFolder.Size;
Console.WriteLine("totalSpace " + freeSpace);
return freeSpace;
}
I am working on the functionality where I need to saw user an alert if storage space is less than a threshold value. I am not getting accurate storage space so my functionality is not working.
My device has total 32 GB storage memory but when I check with above code, it saw 31989469184 bytes which is near 31.98 GB (31989469184/1000/1000/1000) which looks near to correct.But similarly Device's free space is 14.2 GB and with above code it saw 12259602432 bytes which is near 12.25 GB. I am not sure why it is giving 2 GB less.
Above linked android code works well. How can I calculate accurate free space in iOS?
As commented above, iOS keep some memory in cache, I filled full memory of device so that only 300 MB free space left in device. At that time I get the accurate status. So I would suggest if anyone working on functionality mention in question area try filling full your ios device and then test. Following is my final code for both platforms.
Android Code
public double GetRemainingInternalMemoryStorage()
{
//Using StatFS
var path = new StatFs(System.Environment.GetFolderPath(System.Environment.SpecialFolder.LocalApplicationData));
long blockSize = path.BlockSizeLong;
long avaliableBlocks = path.AvailableBlocksLong;
double freeSpace = blockSize * avaliableBlocks;
freeSpace = Math.Round(freeSpace / (1024 * 1024), 1); // Converting freespace to mb. Android follows binary pattern, so divide by 1024.
return freeSpace;
}
iOS Code
public double GetRemainingInternalMemoryStorage()
{
NSFileSystemAttributes applicationFolder = NSFileManager.DefaultManager.GetFileSystemAttributes(Environment.GetFolderPath(Environment.SpecialFolder.Personal));
double freeSpace = applicationFolder.FreeSize;
freeSpace = Math.Round(freeSpace / (1000 * 1000), 1); // Converting freespace to mb. iOS follows decimal pattern, so divide by 1000
return freeSpace;
}
这篇关于获取ios内部存储内存信息xamarin forms ios的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!