My iPhone app (http://hexalex.com) is not universal but it has a feature that I'd like to enable for people playing on iPads. Is there some way to detect that you're running on an iPad in compatibility mode? The UIDevice methods for detecting machine specs all return the values you would get on an iPhone (on the simulator at least). The only thing I can think of is detecting OS 3.2, but that technique won't work for long.
1) Use UIDevice-Extension written by Erica Sadun. A very comprehensive class: http://github.com/erica/uidevice-extension/blob/master/UIDevice-Hardware.m
2) Or you could also use the UIDevice class method:
[[UIDevice currentDevice] name] // eg. "Brock's iPhone"
[[UIDevice currentDevice] model] // eg. @"iPhone", @"iPod Touch"
[[UIDevice currentDevice] localizedModel] // localized version of model
[[UIDevice currentDevice] systemName] // eg. @"iPhone OS"
[[UIDevice currentDevice] systemVersion] // eg. @"3.2"
[[UIDevice currentDevice] uniqueIdentifier] // UDID, a unique string to identify the device
Each of the above lines will return an NSString
. To which you can do a string comparison like so:
NSString *model = [[UIDevice currentDevice] model];
NSLog(@"Current device model: \"%@\"", model);
3) Another way:
http://www.drobnik.com/touch/2009/07/determining-the-hardware-model/ You will need to modify this to use the right hardware number for the iPad. Taken from the link above:
UIDevice-hardware.h
#import
#define IPHONE_1G_NAMESTRING @"iPhone 1G"
#define IPHONE_3G_NAMESTRING @"iPhone 3G"
#define IPHONE_3GS_NAMESTRING @"iPhone 3GS"
#define IPOD_1G_NAMESTRING @"iPod touch 1G"
#define IPOD_2G_NAMESTRING @"iPod touch 2G"
@interface UIDevice (Hardware)
- (NSString *) platform;
- (NSString *) platformString;
@end
UIDevice-hardware.m
#import "UIDevice-hardware.h"
#include <sys/types.h>
#include <sys/sysctl.h>
@implementation UIDevice (Hardware)
/*
Platforms
iPhone1,1 = iPhone 1G
iPhone1,2 = iPhone 3G
iPhone2,1 = iPhone 3GS
iPod1,1 = iPod touch 1G
iPod2,1 = iPod touch 2G
*/
- (NSString *) platform
{
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;
}
- (NSString *) platformString
{
NSString *platform = [self platform];
if ([platform isEqualToString:@"iPhone1,1"]) return IPHONE_1G_NAMESTRING;
if ([platform isEqualToString:@"iPhone1,2"]) return IPHONE_3G_NAMESTRING;
if ([platform isEqualToString:@"iPhone2,1"]) return IPHONE_3GS_NAMESTRING;
if ([platform isEqualToString:@"iPod1,1"]) return IPOD_1G_NAMESTRING;
if ([platform isEqualToString:@"iPod2,1"]) return IPOD_2G_NAMESTRING;
return NULL;
}
@end
Did you check the "UIDevice.h" ? It has model property which u can find-out the iPhone,iPod,iPad devices
NSString *name; // e.g. "My iPhone"
NSString *model; // e.g. @"iPhone", @"iPod Touch"
NSString *localizedModel; // localized version of model
NSString *systemName; // e.g. @"iPhone OS"
NSString *systemVersion; // e.g. @"2.0"
NSString *uniqueIdentifier; // a string unique to each device based on various hardware info.