檢測特定的iPhone/iPodtouch型號我正在制作一個游戲,利用iphone(可能還有iPodtouch第二代)的點對點藍牙功能。然而,為了阻止用戶在iPod1Gen和iPhone2G上玩多人游戲,我需要檢查特定的設備型號。[UIDevicecurrentDevice]型號]只會告訴我這款設備是“iPhone”還是“iPodtouch”。有沒有辦法檢查具體的設備型號,比如“iPhone3GS”、“iPodTouch第一代”等等。編輯:UIDevice有一個類別(我認為它是由EricaSadun創建的,我不認為它值得稱贊),它使用下面的代碼來獲得特定的設備模型。您可以在這里找到整個類別以及其他有用的內容: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。
3 回答

暮色呼如
TA貢獻1853條經驗 獲得超9個贊
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 關注
- 630 瀏覽
添加回答
舉報
0/150
提交
取消