특정 iPhone/iPod Touch 모델 감지 [중복
-
12-09-2019 - |
문제
가능한 복제 :
iOS로 장치 (iPhone, iPod Touch) 결정
iPhone의 P2P Bluetooth 기능 (및 iPod Touch 2nd Generation)의 피어 투 피어 블루투스 기능을 사용하는 게임을 만들고 있습니다. 그러나 사용자가 iPod 1 Gen 및 iPhone 2G에서 멀티 플레이어를 재생하려는 것을 막으려면 특정 장치 모델을 확인해야합니다.
[uidevice currentDevice] 모델]은 장치가 "iPhone"또는 "iPod touch"인 경우에만 알려줍니다. "iPhone 3GS", "iPod Touch 1st Generation"또는 Something과 같은 특정 장치 모델을 확인하는 방법이 있습니까?
편집하다:
UideVice에 대한 카테고리가 있습니다 (Erica Sadun이 작성했다고 생각합니다. 특정 장치 모델을 얻기 위해 다음 코드를 사용합니다. 다른 유용한 것들과 함께 전체 카테고리를 찾을 수 있습니다. 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에서 승인되었습니다.
해결책
가장 완전한 uidevice (하드웨어) 카테고리는 아마도입니다 http://github.com/erica/uidevice-extension/ (Erica Sadun) :
[[UIDevice currentDevice] platformType] // ex: UIDevice4GiPhone
[[UIDevice currentDevice] platformString] // ex: @"iPhone 4G"
다른 팁
장치 모델 번호를 사용하여 얻을 수 있습니다 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
이 코드는 어떻습니까, 새 버전이 출시되면 Last Know Device를 식별합니다.
#include <sys/types.h>
#include <sys/sysctl.h>
- (NSString *)getModel {
size_t size;
sysctlbyname("hw.machine", NULL, &size, NULL, 0);
char *model = malloc(size);
sysctlbyname("hw.machine", model, &size, NULL, 0);
NSString *sDeviceModel = [NSString stringWithCString:model encoding:NSUTF8StringEncoding];
free(model);
if ([sDeviceModel isEqual:@"i386"]) return @"Simulator"; //iPhone Simulator
if ([sDeviceModel isEqual:@"iPhone1,1"]) return @"iPhone1G"; //iPhone 1G
if ([sDeviceModel isEqual:@"iPhone1,2"]) return @"iPhone3G"; //iPhone 3G
if ([sDeviceModel isEqual:@"iPhone2,1"]) return @"iPhone3GS"; //iPhone 3GS
if ([sDeviceModel isEqual:@"iPhone3,1"]) return @"iPhone4 AT&T"; //iPhone 4 - AT&T
if ([sDeviceModel isEqual:@"iPhone3,2"]) return @"iPhone4 Other"; //iPhone 4 - Other carrier
if ([sDeviceModel isEqual:@"iPhone3,3"]) return @"iPhone4"; //iPhone 4 - Other carrier
if ([sDeviceModel isEqual:@"iPhone4,1"]) return @"iPhone4S"; //iPhone 4S
if ([sDeviceModel isEqual:@"iPhone5,1"]) return @"iPhone5"; //iPhone 5 (GSM)
if ([sDeviceModel isEqual:@"iPod1,1"]) return @"iPod1stGen"; //iPod Touch 1G
if ([sDeviceModel isEqual:@"iPod2,1"]) return @"iPod2ndGen"; //iPod Touch 2G
if ([sDeviceModel isEqual:@"iPod3,1"]) return @"iPod3rdGen"; //iPod Touch 3G
if ([sDeviceModel isEqual:@"iPod4,1"]) return @"iPod4thGen"; //iPod Touch 4G
if ([sDeviceModel isEqual:@"iPad1,1"]) return @"iPadWiFi"; //iPad Wifi
if ([sDeviceModel isEqual:@"iPad1,2"]) return @"iPad3G"; //iPad 3G
if ([sDeviceModel isEqual:@"iPad2,1"]) return @"iPad2"; //iPad 2 (WiFi)
if ([sDeviceModel isEqual:@"iPad2,2"]) return @"iPad2"; //iPad 2 (GSM)
if ([sDeviceModel isEqual:@"iPad2,3"]) return @"iPad2"; //iPad 2 (CDMA)
NSString *aux = [[sDeviceModel componentsSeparatedByString:@","] objectAtIndex:0];
//If a newer version exist
if ([aux rangeOfString:@"iPhone"].location!=NSNotFound) {
int version = [[aux stringByReplacingOccurrencesOfString:@"iPhone" withString:@""] intValue];
if (version == 3) return @"iPhone4"
if (version >= 4) return @"iPhone4s";
}
if ([aux rangeOfString:@"iPod"].location!=NSNotFound) {
int version = [[aux stringByReplacingOccurrencesOfString:@"iPod" withString:@""] intValue];
if (version >=4) return @"iPod4thGen";
}
if ([aux rangeOfString:@"iPad"].location!=NSNotFound) {
int version = [[aux stringByReplacingOccurrencesOfString:@"iPad" withString:@""] intValue];
if (version ==1) return @"iPad3G";
if (version >=2) return @"iPad2";
}
//If none was found, send the original string
return sDeviceModel;
}
BOOL hasHighResScreen = NO;
if ([UIScreen instancesRespondToSelector:@selector(scale)]) {
CGFloat scale = [[UIScreen mainScreen] scale];
if (scale > 1.0) {
hasHighResScreen = YES;
}
}
iPhone 4는 iPhone3,1 및 iPhone3,2입니다
iPhone 4S는 iPhone4,1입니다
iPad 2는 버전 (GSM 등)에 따라 iPad2,1 iPad2,2 및 iPad2,3입니다.
iPad 3은 버전 (GSM 등)에 따라 iPad3,1 iPad3,2 및 iPad3,3입니다.
보다 iPhone 비밀 ( "내부 제품 코드"로 스크롤)
또 다른 좋은 출처는 다음과 같습니다.EveryPhone.com
NSString* valueDevice = [[UIDevice currentDevice] model];
그런 다음 문자열이 원하는 장치와 같은지 확인하십시오.
if(value==@"iPod1,1" )
{}
그리고 당신은 가기에 좋을 것입니다