Am unable to identify the device models (iphone , ipad ,ipod touch, iphpne simulator) while programming (in 3.2 version). Alreay am tried with UIDevice Class and some other mean开发者_如何学Gos, but am unable to get model as ipad when connected to ipad. every time it is giving model other than ipad. So can any one please help me out. Thank you.
I've used this code and it works really well:
size_t size;
sysctlbyname("hw.machine", NULL, &size, NULL, 0);
char *machine = malloc(size);
sysctlbyname("hw.machine", machine, &size, NULL, 0);
NSString *platform = [NSString stringWithCString:machine];
free(machine);
return platform;
This come from arstechnica.com.
The general approach is to avoid trying to guess device models by yourself. In most of the cases (but you didn't described your original need), the framework provides you the HW capabilities from the API and you don't really have to know which models you're using in reality.
For instance, if you want to know if a camera is available, you're not going to check in your code if (model==iphone3G || model==iPhone3Gs)
You're just going to ask something like [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]
that is part of the public API.
I think you might want to check [UIDevice userInterfaceIdiom]. On either the iPad or the iPad sim this will return UIUserInterfaceIdiomPad. On other devices or sims it will return UIUserInterfaceIdiomPhone.
精彩评论