Sysctl () and Sysctlbyname () Allow access to system information. These standard UNIX functions are used to interrogate the operating system for details about hardware and OS.
These constants allow you to check core information, such as the CPU frequency of the system, the amount of memory available, and so on. It introduces a Uidevice class that collects system information and returns it through a series of method calls.
Each model offers a unique built-in capability to know exactly which iphone you're working with to help determine if the unit is likely to support features such as accessibility, GPS, and magnetometers.
#pragmaMark Sysctlbyname utils-(NSString *) Getsysinfobyname: (Char*) typespecifier{size_t size; Sysctlbyname (Typespecifier, NULL,&size, NULL,0); Char*answer =malloc (size); Sysctlbyname (Typespecifier, answer,&size, NULL,0); NSString*results =[NSString stringwithcstring:answer encoding:nsutf8stringencoding]; Free (answer); returnresults;}-(NSString *) platform{return[Self Getsysinfobyname:"Hw.machine"];}//Thanks, Tom Harrington (Atomicbird)-(NSString *) hwmodel{return[Self Getsysinfobyname:"Hw.model"];}
The returned is:
--:40.391 helloworld[2673: 943598] Platform:iphone5,4--: 40.393 helloworld[2673:943598] Hwmodel:n49ap
#pragmaMark Sysctl utils-(Nsuinteger) Getsysinfo: (UINT) typespecifier{size_t size=sizeof(int); intresults; intmib[2] ={CTL_HW, typespecifier}; Sysctl (MIB,2, &results, &size, NULL,0); return(Nsuinteger) results;}-(Nsuinteger) cpufrequency{return[self getsysinfo:hw_cpu_freq];}-(Nsuinteger) busfrequency{return[self getsysinfo:hw_bus_freq];}-(Nsuinteger) cpucount{return[self getsysinfo:hw_ncpu];}-(Nsuinteger) totalmemory{return[self getsysinfo:hw_physmem];}-(Nsuinteger) usermemory{return[self getsysinfo:hw_usermem];}-(Nsuinteger) maxsocketbuffersize{return[self getsysinfo:kipc_maxsockbuf];}
View disk space
-(NSNumber *) totaldiskspace{ *fattributes = [[Nsfilemanager Defaultmanager] Attributesoffilesystemforpath:nshomedirectory () Error:nil]; return [Fattributes objectforkey:nsfilesystemsize];} -(NSNumber *) freediskspace{ *fattributes = [[Nsfilemanager Defaultmanager] Attributesoffilesystemforpath:nshomedirectory () Error:nil]; return [Fattributes objectforkey:nsfilesystemfreesize];}
IOS device-specific development: get additional device information