Possible Duplicate:
Determine device (iPhone, iPod Touch) with iOS
我正在制作一款利用iPhone(可能还有iPod touch第二代)的点对点蓝牙功能的游戏.然而,为了阻止用户try 在iPod第一代和iPhone2G上玩多人游戏,我需要判断特定的设备型号.
[[UIDevice currentDevice]型号]只会告诉我设备是"iPhone"还是"iPod touch".有没有办法判断具体的设备型号,比如:"iPhone3GS"、"iPod touch 1代"或其他什么.
EDIT:个
UIDevice有一个类别(我认为它是由Erica Sadun创建的,我不认为这是值得称赞的),它使用以下代码来获得特定的设备型号.你可以在这里找到整个类别以及其他有用的东西: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中获得批准.