检测特定的iPhone / iPod touch型号 [英] Detect the specific iPhone/iPod touch model

查看:133
本文介绍了检测特定的iPhone / iPod touch型号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

使用iPhone SDK确定设备(iPhone,iPod Touch)

我正在制作一款利用iPhone的对等蓝牙功能的游戏(可能还有iPod touch第二代)。但是,要阻止用户尝试在iPod 1st和iPhone 2G上播放多人游戏,我需要检查特定的设备型号。

I am making a game that utilizes the peer-to-peer bluetooth capabilities of the iPhone (and probably the iPod touch 2nd generation). However, to stop the users from trying to play a multiplayer on an iPod 1st gen and iPhone 2G I need to check for the specific device model.

[[UIDevice currentDevice] model]只会告诉我该设备是iPhone还是iPod touch。有没有办法检查特定的设备型号,如:iPhone 3GS,iPod touch 1st generation或其他什么。

[[UIDevice currentDevice] model] will only tell me if the device is an "iPhone" or an "iPod touch". Is there a way to check for the specific device model, like: "iPhone 3GS", "iPod touch 1st generation" or something.

编辑:

UIDevice有一个类别(我认为它是由Erica Sadun创建的,我不赞成它),它使用以下代码来获取具体信息设备模型。您可以在此处找到整个类别以及其他有用的内容: https://github.com/erica/uidevice -extension

There is a category to UIDevice (I think it's created by Erica Sadun, I don't take credit for it) that uses the following code to get the specific device model. You can find the whole category here along with other useful stuff: https://github.com/erica/uidevice-extension

#include <sys/types.h>
#include <sys/sysctl.h>

@implementation UIDevice (Hardware)

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

- (NSString *) platform
{
  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);
  return platform;
}

此作品和使用此功能的应用程序最近已在AppStore中获得批准。

This works and apps using this have been lately approved in the AppStore.

推荐答案

最完整的UIDevice(硬件)类别可能是 http://github.com/erica/uidevice-extension/ (作者Erica Sadun):

Most complete UIDevice (Hardware) category probably is http://github.com/erica/uidevice-extension/ (by Erica Sadun):

[[UIDevice currentDevice] platformType]   // ex: UIDevice4GiPhone
[[UIDevice currentDevice] platformString] // ex: @"iPhone 4G"

这篇关于检测特定的iPhone / iPod touch型号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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