Skip to content

Instantly share code, notes, and snippets.

@mogwai
Created October 9, 2017 10:42
Show Gist options
  • Save mogwai/6598138c623fc027e0e02a917c8ab571 to your computer and use it in GitHub Desktop.
Save mogwai/6598138c623fc027e0e02a917c8ab571 to your computer and use it in GitHub Desktop.
namespace MyApp.Helpers {
public static class DeviceInformation {
/// <summary>
/// Finds out whether this is a low memory device using a Dependency Service
/// </summary>
[Preserve]
public static bool LowMemoryDevice {
get {
var mem = DependencyService.Get<IMemoryHelper>().GetTotalMemory();
mem = mem / (1000 * 1000);// To megabytes
Debug.WriteLine($"Total Memory: {mem}MB");
return mem < 500;
}
}
}
}
[assembly:Dependency(typeof(MemoryHelper))]
namespace MyApp.iOS.Helpers {
[Preserve(AllMembers = true)]
public class MemoryHelper : IMemoryHelper {
public MemoryHelper() { }
public ulong GetTotalMemory() {
return NSProcessInfo.ProcessInfo.PhysicalMemory;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment