0
votes

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 means, 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.

3
A piece of code showing how you try to obtain the model might help. Also if you are actually running on a physical iPad of from the simulator.Claus Broch
Have you used [UIDevice model]?notnoop

3 Answers

1
votes

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.

0
votes

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.

0
votes

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.