Possible Duplicate:
Determine device (iPhone, iPod Touch) with iOS

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] 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.

EDIT:

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;
}

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

推荐答案

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"

Ios相关问答推荐

如何删除NavigationView中的默认透明标头?

当 .searchable 修饰符处于活动状态时,如何将变量设置为 false?

Swift Vision库识别文本后如何将其赋值给 struct 体实例属性以供显示?

尽管存在浮点错误,如何显示正确的计算结果.计算器应用程序

SwiftUI - 如何从主题感知命名 colored颜色 中获取正确的 RGB 值?

弹出视图后使所有背景 UI 模糊

如何为视图的 colored颜色 和宽度设置动画?

Apple Push Service 证书不受信任

如何找出坐标之间的距离?

无法将NSTaggedPointerString类型的值转换为NSNumber

UIView 动画与 CALayers

用户拒绝使用后如何提示用户打开位置服务

iPhone:什么是 WWDR 中级证书?

如果我的分发证书过期会怎样?

用 NavigationViewController 快速呈现 ViewController

打开 XIB 文件后 Xcode 6.3 冻结/挂起

我的应用程序因使用广告支持框架而被拒绝.哪个图书馆负责?

在自动布局中居中子视图的 X 会引发未准备好约束

为什么 UITableViewAutomaticDimension 不起作用?

以编程方式导航到另一个视图控制器/场景