IOS device-specific development: get additional device information

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.