IOS獲取手機與屏幕屬性
在次之前,補充個內容。UIDevice是無法獲得具體的設備型號的。
要獲得設備型號,比如(iphone 4s, iphone5)這樣的,要通過這樣的辦法。
1.引入頭文件。
#include <sys/types.h>
#include <sys/sysctl.h>
2.獲取型號
//手機型號。 size_t size; sysctlbyname("hw.machine", NULL, &size, NULL, 0); char *machine = (char*)malloc(size); sysctlbyname("hw.machine", machine, &size, NULL, 0); NSString *platform = [NSString stringWithCString:machine encoding:NSUTF8StringEncoding];
這里得到的platform是個設備型號。 比如iphone5,2.
所以如果想更完美點,可以自己根據字符串判斷。
比如: if ([platform isEqualToString:@"iPhone3,1"]) return @"iPhone 4";
一.UIDevice
//設備相關信息的獲取 NSString *strName = [[UIDevice currentDevice] name]; NSLog(@"設備名稱:%@", strName);//e.g. "My iPhone" NSString *strId = [[UIDevice currentDevice] uniqueIdentifier]; NSLog(@"設備唯一標識:%@", strId);//UUID,5.0后不可用 NSString *strSysName = [[UIDevice currentDevice] systemName]; NSLog(@"系統名稱:%@", strSysName);// e.g. @"iOS" NSString *strSysVersion = [[UIDevice currentDevice] systemVersion]; NSLog(@"系統版本號:%@", strSysVersion);// e.g. @"4.0" NSString *strModel = [[UIDevice currentDevice] model]; NSLog(@"設備模式:%@", strModel);// e.g. @"iPhone", @"iPod touch" NSString *strLocModel = [[UIDevice currentDevice] localizedModel]; NSLog(@"本地設備模式:%@", strLocModel);// localized version of model //地方型號(國際化區域名稱) NSString* phoneModel = [[UIDevice currentDevice] model]; NSLog(@"手機型號: %@",phoneModel ); //手機型號
本文由用戶 gww3 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!