方法一:
-(void)defineDeviceType{ extern int deviceType; NSRange rg= [[[UIDevice currentDevice].model lowercaseString]rangeOfString:@"iphone"]; if(rg.location!=NSNotFound){ deviceType=0; return; } rg= [[[UIDevice currentDevice].model lowercaseString]rangeOfString:@"ipad"]; if(rg.location!=NSNotFound){ deviceType=1; return; } rg= [[[UIDevice currentDevice].model lowercaseString]rangeOfString:@"ipod"]; if(rg.location!=NSNotFound){ deviceType=2; return; } deviceType=-1; // NSLog(@"%@",[UIDevice currentDevice].model);//iPhone Simulator iPod touch // NSLog(@"%@",[UIDevice currentDevice].name);//name you defined // NSLog(@"%@",[UIDevice currentDevice].systemName);//iPhone OS // NSLog(@"%@",[UIDevice currentDevice].systemVersion);//version of OS }
这个比较全面的获得各种信息,还是不错的。
方法二:
- (NSString *) platform { size_t size; // get the length of machine name sysctlbyname("hw.machine", NULL, &size, NULL, 0); // get machine name char *machine = malloc(size); sysctlbyname("hw.machine", machine, &size, NULL, 0); NSString *platform = [NSString stringWithCString:machine]; free(machine); return platform; }
能获得类似iPod4,1的信息,从而知道机器版本,但是没有办法获得ios版本