你如何使用Obj C检测iPhone v.iPhone 3G [英] How do you detect iPhone v. iPhone 3G using Obj C

查看:52
本文介绍了你如何使用Obj C检测iPhone v.iPhone 3G的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

该设备有一个型号属性,但它不区分iPhone和iPhone 3G。还有更好的方法吗?

There is a model property of the device, but it doesn't distinguish between iPhone and iPhone 3G. Is there a better way?

推荐答案

Stephan发布的项目特别有趣的部分是:

The specifically interesting parts of the project Stephan posted are these:

您可能会看到的字符串值:

The string values you're likely to see:

/*
 Platforms
 iPhone1,1 -> iPhone 1G
 iPhone1,2 -> iPhone 3G 
 iPod1,1   -> iPod touch 1G 
 iPod2,1   -> iPod touch 2G 
*/

如何获得其中一个值:

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 encoding: NSUTF8StringEncoding];

free(machine);

然后你可以检查 @iPhone平台的开头 @iPod并告诉您是否有带GPS的设备。我不建议将整个字符串与您想要的匹配,因为下次设备出现时(例如今年夏天,很可能),如果不更改代码,您将无法匹配它。

You can then check the beginning of platform for @"iPhone" or @"iPod" and tell if you have a device with GPS or not. I wouldn't recommend matching the whole string for what you want, because the next time a device comes out (such as this summer, most likely) you won't be able to match it without changing code.

此外,如果你还没有看到它们,Erica Sadun(项目作者)在iPhone开发方面有一些很好的文章 ArsTechnica.com 以及至少一本关于它的书。

Also, if you haven't seen them, Erica Sadun (the project author) has some excellent articles on iPhone dev at ArsTechnica.com and at least one book about it.

这篇关于你如何使用Obj C检测iPhone v.iPhone 3G的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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