import "UIDevice+Category.h"
import <sys/mount.h>
@implementation UIDevice (Category)
-
(CGFloat)deviceGetBatteryQuantity {
[UIDevice currentDevice].batteryMonitoringEnabled = YES;
return ([[UIDevice currentDevice] batteryLevel]) * 100;
} -
(long long)deviceGetTotalMemorySize {
return [NSProcessInfo processInfo].physicalMemory;
} -
(long long)deviceGetTotalDiskSize {
struct statfs buf;
unsigned long long freeSpace = -1;
if (statfs("/var", &buf) >= 0)
{
freeSpace = (unsigned long long)(buf.f_bsize * buf.f_blocks);
}
return freeSpace;
} -
(long long)deviceGetAvailableDiskSize {
struct statfs buf;
unsigned long long freeSpace = -1;
if (statfs("/var", &buf) >= 0)
{
freeSpace = (unsigned long long)(buf.f_bsize * buf.f_bavail);
}
return freeSpace;
}
/******************************/
import "ViewController.h"
import "UIDevice+Category.h"
@interface ViewController ()
@end
@implementation ViewController
-
(void)viewDidLoad {
[super viewDidLoad];CGFloat battery = [UIDevice deviceGetBatteryQuantity];
long long memorySize = [UIDevice deviceGetTotalMemorySize];
long long diskSize = [UIDevice deviceGetTotalDiskSize];
long long availableDiskSize = [UIDevice deviceGetAvailableDiskSize];
NSLog(@"\n battery:%f \n memorySize:%lld \n diskSize:%lld \n availableDiskSize:%lld ",battery,memorySize,diskSize,availableDiskSize);
/**
battery:100.000000
memorySize:1048576000
diskSize:12075704320
availableDiskSize:3585474560
*/
}
网友评论