The iOS framework that grows only as fast as its documentation
NIDeviceInfo Class Reference

Overview

An interface for accessing device information.

This class is not meant to be instantiated. All methods are class implementations.

This class aims to simplify the interface for collecting device information. The low-level mach APIs provide a host of valuable information but it's often in formats that aren't particularly ready for presentation.

Attention
When using this class on the simulator, the values returned will reflect those of the computer within which you're running the simulator, not the simulated device. This is because the simulator is a first-class citizen on the computer and has full access to your RAM and disk space.

Tasks

Memory
(unsigned long long) + bytesOfFreeMemory
 
(unsigned long long) + bytesOfTotalMemory
 
(void) + simulateLowMemoryWarning
 
Disk Space
(unsigned long long) + bytesOfFreeDiskSpace
 
(unsigned long long) + bytesOfTotalDiskSpace
 
Battery
(CGFloat) + batteryLevel
 
(UIDeviceBatteryState) + batteryState
 
Caching
(BOOL) + beginCachedDeviceInfo
 
(void) + endCachedDeviceInfo
 

Method Documentation

bytesOfFreeMemory

The number of bytes in memory that are free.

+ (unsigned long long)bytesOfFreeMemory;
Discussion

Calculated using the number of free pages of memory.

bytesOfTotalMemory

The total number of bytes of memory.

+ (unsigned long long)bytesOfTotalMemory;
Discussion

Calculated by adding together the number of free, wired, active, and inactive pages of memory.

This value may change over time on the device due to the way iOS partitions available memory for applications.

simulateLowMemoryWarning

Simulate low memory warning.

+ (void)simulateLowMemoryWarning;
Discussion

Don't use this in production because it uses private API

bytesOfFreeDiskSpace

The number of bytes free on disk.

+ (unsigned long long)bytesOfFreeDiskSpace;

bytesOfTotalDiskSpace

The total number of bytes of disk space.

+ (unsigned long long)bytesOfTotalDiskSpace;

batteryLevel

The battery charge level in the range 0 .

+ (CGFloat)batteryLevel;
Discussion

. 1.0. -1.0 if UIDeviceBatteryStateUnknown.

This is a thin wrapper for [[UIDevice currentDevice] batteryLevel].

batteryState

The current battery state.

+ (UIDeviceBatteryState)batteryState;
Discussion

This is a thin wrapper for [[UIDevice currentDevice] batteryState].

beginCachedDeviceInfo

Fetches the device's current information and then caches it.

+ (BOOL)beginCachedDeviceInfo;
Discussion

All subsequent calls to NIDeviceInfo methods will use this cached information.

This can be a useful way to freeze the device info at a moment in time.

Example:

// All calls to NIDeviceInfo methods here will use the information retrieved when
// beginCachedDeviceInfo was called.

endCachedDeviceInfo

Stop using the cache for the device info methods.

+ (void)endCachedDeviceInfo;