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

问题描述

可能的重复:
使用 iOS 确定设备(iPhone、iPod Touch)

我正在制作一款利用 iPhone(可能还有第 2 代 iPod touch)的点对点蓝牙功能的游戏.但是,为了阻止用户尝试在 iPod 1st gen 和 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-扩展

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 (Hardware) 类别大概是 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 型号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-29 07:18