检测特定的 iPhone/iPod touch 型号

编程入门 行业动态 更新时间:2024-10-25 04:20:33
本文介绍了检测特定的 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 创建的,我不认为是它的功劳)它使用以下代码来获取特定的设备型号.您可以在此处找到整个类别以及其他有用的内容:github/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: 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 (Hardware) 类别大概是 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 型号

本文发布于:2023-08-01 15:43:12,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1269583.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:型号   iPhone   iPod   touch

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!