年前,一直在做IOS前端数据采集这一块。。所以就整理了下,这些用到的东西...后继有可能还有补充
1.CPU类型获取
需要引入以下头文件,CPU类型放在 mach/machine.h中
#include <sys/types.h>
#include <sys/sysctl.h>
#include <mach/machine.h>
+(NSString*)getCPUType
{
NSMutableString *cpu = [[NSMutableString alloc] init];
size_t size;
cpu_type_t type;
cpu_subtype_t subtype;
size = sizeof(type);
sysctlbyname("hw.cputype", &type, &size, NULL, 0);
size = sizeof(subtype);
sysctlbyname("hw.cpusubtype", &subtype, &size, NULL, 0);
// values for cputype and cpusubtype defined in mach/machine.h
if (type == CPU_TYPE_X86)
{
[cpu appendString:@"x86 "];
// check for subtype ...
} else if (type == CPU_TYPE_ARM)
{
[cpu appendString:@"ARM"];
[cpu appendFormat:@",Type:%d",subtype];
}
return [cpu autorelease];
}
2.获取设备总内存
+ (NSUInteger)getTotalMemoryBytes
{
size_t size = sizeof(int);
int results;
int mib[2] = {CTL_HW, HW_PHYSMEM};
sysctl(mib, 2, &results, &size, NULL, 0);
return (NSUInteger) results/1024/1024;
}
3.获取当前应用所占得内存
+(double)getCurrentApplicationUseMemory
{
task_basic_info