可能重复: 使用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创建的,我不赞成它),它使用以下代码来获取具体信息设备模型。您可以在此处找到整个类别以及其他有用的内容: github/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: github/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(硬件)类别可能是 github/erica/uidevice-extension/ (作者Erica Sadun):
Most complete UIDevice (Hardware) category probably is github/erica/uidevice-extension/ (by Erica Sadun):
[[UIDevice currentDevice] platformType] // ex: UIDevice4GiPhone [[UIDevice currentDevice] platformString] // ex: @"iPhone 4G"更多推荐
检测特定的iPhone / iPod touch型号
发布评论