Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
167 views
in Technique[技术] by (71.8m points)

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

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...