如何判断您的代码是在iPhone还是iPhone3G上运行? [英] How to tell if your code is running on an iPhone or an iPhone3G?

查看:87
本文介绍了如何判断您的代码是在iPhone还是iPhone3G上运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试确定我的代码是在iPhone还是iPhone3G上运行。我的第一次尝试是在UIKit中使用UIDevice类,但iPhone和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

这些是UIDevice允许您查询的唯一参数。

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?

推荐答案

iPhone运行OS X. 这里是如何在Macintosh桌面上确定您的硬件平台。在iPhone上这里是。这是完全相同的。

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.

简而言之, sysctlbyname(hw.machine,str,sz,0,0)会将平台名称写入 str 。对于iPhone和iPhone 3G,这恰好分别是iPhone1,1或iPhone1,2。

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.

这篇关于如何判断您的代码是在iPhone还是iPhone3G上运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆