- (Nsstring *) getSysInfoByname:(char *)typespecifIEr{ size_t size; sysctlbyname(typespecifIEr,NulL,&size,0); char *answer = malloc(size); sysctlbyname(typespecifIEr,answer,0); Nsstring *results = [Nsstring stringWithCString:answer enCoding: NSUTF8StringEnCoding]; free(answer); return results;}- (Nsstring *) platform{ return [self getSysInfoByname:"hw.machine"];}
在实际开发中,有时需要考虑到兼容性问题,这两个信息还是很有用的,我一般都是程序开始时读取,存到公共变量里。#import "sys/utsname.h" /*! * get the information of the device and system * "i386" simulator * "iPod1,1" iPod touch * "iPhone1,1" iPhone * "iPhone1,2" iPhone 3G * "iPhone2,1" iPhone 3GS * "iPad1,1" iPad * "iPhone3,1" iPhone 4 * @return null */- (voID)getDeviceAndOSInfo{ //here use sys/utsname.h struct utsname systemInfo; uname(&systemInfo); //get the device model and the system version NSLog(@"%@",[Nsstring stringWithCString:systemInfo.machine enCoding:NSUTF8StringEnCoding]); NSLog(@"%@",[[UIDevice currentDevice] systemVersion]);}总结
以上是内存溢出为你收集整理的获取系统硬件信息全部内容,希望文章能够帮你解决获取系统硬件信息所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)