I looked around to find, how I can know on which iPhone my App is running (iPhone 3G, iPhone3GS, iPhone 4) to do additional things depending on the exactly device. The preferred method was mostly something like this:
size_t size;
sysctlbyname("hw.machine", NULL, &size, NULL, 0);
char *name = (ch开发者_开发问答ar *)malloc(size);
sysctlbyname("hw.machine", name, &size, NULL, 0);
NSString *machine = [NSString stringWithCString:name];
free(name);
if([machine compare:@"iPhone3,1"]==NSOrderedSame){
//iPhone 4
}else if([machine compare:@"i386"]==NSOrderedSame){
//Simulator
}else{
//iPhone 3GS, 3G...
}
NSLog(@"Device %@", machine);
This worked fine so far, but now we updated X-Code and the simulator. So its possible to run the Simulator as iPhone 4, iPhone3GS or iPhone3G. How can this be detected at runtime? Any solutions or workarounds so far?
Edit: Even a solution like here http://iphonedevelopment.blogspot.com/2009/05/device-detection.html of course isn't working properly anymore, since an simulator can be also an iPhone4!
Never coded for iPhone, but I Googled and found this: Apple Developer: UIDevice Class
Or maybe this helps: iPhone - How do I detect the iPhone version?
精彩评论