iPhoneSettings.model isn't enough - I need the exact device!

The docs say iPhoneSettings.model only returns ‘iPhone’ or ‘iPod Touch’. This is not enough! How do I get the exact model? I need to know if it’s an iPhone 3G, 3GS, iPod Touch 2nd Gen, etc…

I’m trying to make sure every device has optimal performance.

I know this could cause problems as new devices are added, but the way I was planning to do this was to have a default minimal setup for 1st gen and unknown devices and enable additional graphical fluff for known, more powerful devices…

any ideas?

If it’s available from the API, just find out in the ObjectiveC start up code and write it to a playerpref setting for use in Unity.

Apple’s SDK’s (i.e. [[UIDevice currentDevice] model]) just returns “iPhone” or “iPod Touch” – and that’s it. My 3GS is an “iPhone”. Luckily Erica Sadun at ArsTechnica made a nice UIDevice category that uses sysctl() to get a better name: http://arstechnica.com/apple/guides/2009/03/iphone-dev-determining-your-platform.ars

Add her two files to your project, and then in your applicationDidFinishLaunching: add this:

   [[NSUserDefaults standardUserDefaults] setObject: [[UIDevice currentDevice] platformString] forKey: @"platform"];

And when your Unity game starts you’ll have a nice string like “iPhone 3G” in the player prefs. Erica’s code predates the 3GS, so you can add this to her header:

#define IPHONE_3GS_NAMESTRING @"iPhone 3GS"

and add this to the logical spot in platformString:

	if ([platform isEqualToString:@"iPhone2,1"]) return IPHONE_3GS_NAMESTRING;

And you should be set.

bliprob comes through again! Sweet.

great, thx, rob! works like a charm. (can’t test with 3GS though yet…)

I put the first line into PreInit though… so it is amongst friends…

Is there a way to automate the process of adding these two files? If I drop them into the Enhancement-Pack’s XCode-Folder they get copied over, but I get an error when building. If I drag the same two files into XCode manually, it works…

You can edit the AppleScripts, but it’s probably simpler to just add this to the end of AppController+additions.mm:

@implementation UIDevice (stinkbot)

- (NSString *) platform
{
	size_t size;
	sysctlbyname("hw.machine", NULL, &size, NULL, 0);
	char *machine = (char*) 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";
	if ([platform isEqualToString:@"iPhone1,2"]) return @"iPhone 3G";
	if ([platform isEqualToString:@"iPhone2,1"]) return @"iPhone 3GS";
	if ([platform isEqualToString:@"iPod1,1"])   return @"iPod Touch";
	if ([platform isEqualToString:@"iPod2,1"])   return @"iPod Touch 2G";
	if ([platform isEqualToString:@"iPod3,1"])   return @"iPod Touch 3G";
	return NULL;
}
@end

That way you don’t need Erica’s two files, and everything is neatly self-contained in the one file that does get added. (You’ll get a warning in preInit where this is called, since there’s no header, but just ignore the warning for now.)

Note that I added code for the iPod Touch 3G, based on the recent reports of “iPod3,1” being seen in server logs. So you should be slightly future-proofed, too.

thanks a lot!