Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to tell if your code is running on an iPhone or an iPhone3G?

Tags:

I am trying to determine if my code is running on an iPhone or an iPhone3G. My first try was to use the UIDevice class in UIKit, but both iPhone and iPhone3G return the same responses:

NSLog([[UIDevice currentDevice] name]); // Name of the phone as named by user NSLog([[UIDevice currentDevice] uniqueIdentifier]); // A GUID like string NSLog([[UIDevice currentDevice] systemName]); // "iPhone OS"  NSLog([[UIDevice currentDevice] systemVersion]); // "2.2.1" NSLog([[UIDevice currentDevice] model]); // "iPhone" on both devices NSLog([[UIDevice currentDevice] localizedModel]); // "iPhone" on both devices 

Those are the only parameters that UIDevice allows you to query.

I looked a bit in Foundation Framework but have not yet found the appropriate calls.

I'm sure there is some piece of hardware I could query (such as something in location services) but that seems like a hack. Does anyone know a simply way of determining this?

like image 496
Aftermathew Avatar asked Mar 27 '09 00:03

Aftermathew


2 Answers

The iPhone runs OS X. Here's how to determine your hardware platform on a Macintosh desktop. Here's how on an iPhone. It's the same exact thing.

In short, sysctlbyname("hw.machine", str, sz, 0, 0) will write the platform name into str. This happens to be "iPhone1,1" or "iPhone1,2" for the iPhone and iPhone 3G respectively.

like image 110
ephemient Avatar answered Oct 12 '22 10:10

ephemient


I'm not an iPhone developer but checking for the underlying platform instead of platform capabilities is almost always the wrong choice. If the iPhone gains the functionality you need, you will still fail to run. There's also a chance you'll make the wrong decision on the next iPhone 4.0 (or whatever it is called).

like image 29
Steve Rowe Avatar answered Oct 12 '22 11:10

Steve Rowe