檢測(cè)特定的iPhone/iPodtouch型號(hào)我正在制作一個(gè)游戲,利用iphone(可能還有iPodtouch第二代)的點(diǎn)對(duì)點(diǎn)藍(lán)牙功能。然而,為了阻止用戶在iPod1Gen和iPhone2G上玩多人游戲,我需要檢查特定的設(shè)備型號(hào)。[UIDevicecurrentDevice]型號(hào)]只會(huì)告訴我這款設(shè)備是“iPhone”還是“iPodtouch”。有沒(méi)有辦法檢查具體的設(shè)備型號(hào),比如“iPhone3GS”、“iPodTouch第一代”等等。編輯:UIDevice有一個(gè)類(lèi)別(我認(rèn)為它是由EricaSadun創(chuàng)建的,我不認(rèn)為它值得稱(chēng)贊),它使用下面的代碼來(lái)獲得特定的設(shè)備模型。您可以在這里找到整個(gè)類(lèi)別以及其他有用的內(nèi)容: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;}這個(gè)工作和應(yīng)用程序使用這個(gè)最近已經(jīng)批準(zhǔn)在AppStore。
3 回答

暮色呼如
TA貢獻(xiàn)1853條經(jīng)驗(yàn) 獲得超9個(gè)贊
uname
sys/utsname.h
#import <sys/utsname.h>NSString*machineName(){ struct utsname systemInfo; uname(&systemInfo); return [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];}
@"i386" on the simulator @"iPod1,1" on iPod Touch @"iPod2,1" on iPod Touch Second Generation @"iPod3,1" on iPod Touch Third Generation @"iPod4,1" on iPod Touch Fourth Generation @"iPhone1,1" on iPhone @"iPhone1,2" on iPhone 3G @"iPhone2,1" on iPhone 3GS @"iPad1,1" on iPad @"iPad2,1" on iPad 2 @"iPad3,1" on iPad 3 (aka new iPad) @"iPhone3,1" on iPhone 4 @"iPhone4,1" on iPhone 4S @"iPhone5,1" on iPhone 5 @"iPhone5,2" on iPhone 5
- 3 回答
- 0 關(guān)注
- 629 瀏覽
添加回答
舉報(bào)
0/150
提交
取消