Possible Duplicate:
iPhone - How do I detect the iPhone version?
So I looked at this thread: iPhone - How do I detect the iPhone version?
But it doesn't answer how to look for iphone 4. Also, it seems like ugly code. Maybe there's an easier way?
I'm also looking specifically for detecting iphone 4 in code. Any ideas? Thanks!
I do not want to discuss here if it's better to detect the hardware model or the capabilities; I believe that what is best just depends on the particular need one may have. Anyway, if you want to test for the hardware model, then you can use the following unix system call:
#include <sys/utsname.h>
int uname(struct utsname *name);
One of the members of the struct utsname
is machine
, a null terminated string that identifies the hardware (for info about the other members see man 3 uname); in the case of an iPhone 4 it will be "iPhone3,1", for 3GS "iPhone2,1", for 3G "iPhone1,2", for the iPod Touch 4th generation "iPod4,1", third generation "iPod3,1" and second generation "iPod2,1".
struct utsname platform;
int rc;
rc = uname(&platform);
if(rc == -1){
/* handle error */
}
else{
fprintf(stdout, "hardware platform: %s", platform.machine);
}
Don't detect models, detect capabilities.
For instance, if you are downloading an image from a web service which provides @2x images as well as normal sized images, you know that right now, that only works on the iPhone4 and iPod Touch 4, but who's to say that won't work on the iAmazingMagicThingy tomorrow? Test for the capability.
To use the above example, the way to test for that would be:
if([[UIScreen mainScreen] respondsToSelector:@selector(scale)] &&
[[UIScreen mainScreen] scale] == 2.0) {
/* do your thing */
}
I'm not going to go on and on about how to test for capabilities, but you really want to be doing it this way rather than testing for a specific model.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With