ここから解決策を見つけました: iPhone SDKでデバイス(iPhone、iPod Touch)を決定します
リンクから、ライブラリhttps://gist.github.com/1323251を使用することをお勧めします
しかし、明らかにライブラリはかなり古くなっています。リストに iPhone 5 や新しい iPad などは見つかりませんでした。
完成して更新されたリストを見つける方法を知っている人はいますか?
どうもありがとう。
ここから解決策を見つけました: iPhone SDKでデバイス(iPhone、iPod Touch)を決定します
リンクから、ライブラリhttps://gist.github.com/1323251を使用することをお勧めします
しかし、明らかにライブラリはかなり古くなっています。リストに iPhone 5 や新しい iPad などは見つかりませんでした。
完成して更新されたリストを見つける方法を知っている人はいますか?
どうもありがとう。
を簡単に検出でき、iphone
以下の条件で:-iphone5
iPad
if([[UIDevice currentDevice]userInterfaceIdiom]==UIUserInterfaceIdiomPhone)
{
if ([[UIScreen mainScreen] bounds].size.height == 568.0f)
{
}
else
{
//iphone 3.5 inch screen
}
}
else
{
//[ipad]
}
私の答え:- デバイスの種類を検出する
次のコードを使用します。
#import <sys/utsname.h>
- (NSString *)machineName
{
struct utsname systemInfo;
uname(&systemInfo);
NSString *temp = [NSString stringWithCString:systemInfo.machine
encoding:NSUTF8StringEncoding];
if ([temp rangeOfString:@"iPod"].location != NSNotFound)
{
return @"iPod";
}
if ([temp rangeOfString:@"iPad"].location != NSNotFound)
{
return @"iPad";
}
if ([temp rangeOfString:@"iPhone"].location != NSNotFound)
{
return @"iPhone";
}
return @"Unknown device";
}
次のコードを使用できます
if(screenSize.width==2048 && screenSize.height==1536)
{
LetterParams.DeviceType=1;//IPadRetina
}
else if(screenSize.width==2048/2 && screenSize.height==1536/2)
{
LetterParams.DeviceType=2;//IPad Non-Retina
}
else if(screenSize.width==1136 && screenSize.height==640)
{
LetterParams.DeviceType=3;//IPhoneRetina
}
else
{
LetterParams.DeviceType=4;//IPhone & Ipod
}
ここでは、画面測定機能の主要なデバイスに焦点を当てて私が思いついた方法を示します。必要なものをすばやく判断する方法です。これは、iPhone 5 および第 5 世代までの iPod touch を検出します。
typedef enum{
iPadRetina,iPadNoRetina,iPhoneiPod35InchRetina,iPhoneiPod35InchNoRetina,iPhoneiPod4InchRetina}DeviceType;
-(void)yourCustomFunctionThatNeedsToKnowDeviceType
{
NSLog(@"device type = %i",[self getDeviceType]);
switch ([self getDeviceType])
{
case iPadRetina:
{
NSLog(@"This device is one of the following: iPad 3, iPad 4");
break;
}
case iPadNoRetina:
{
NSLog(@"This device is one of the following: iPad 1, iPad 2, iPad mini");
break;
}
case iPhoneiPod35InchRetina:
{
NSLog(@"This device is one of the following: iPhone 4/4S or iPod Touch 4th Generation");
break;
}
case iPhoneiPod35InchNoRetina:
{
NSLog(@"This device is one of the following: iPhone 3G/3GS or iPod Touch 3rd Generation");
break;
}
case iPhoneiPod4InchRetina:
{
NSLog(@"This device is one of the following: iPhone 5 or iPod Touch 5th Generation");
break;
}
}
}
-(int)getDeviceType
{
// Get the ratio of the device's screen (height/width)
CGFloat screenRatio = [UIScreen mainScreen].bounds.size.height/[UIScreen mainScreen].bounds.size.width;
// Initialize return value to negative value
DeviceType type = -1;
if(screenRatio > 1.5)
{
/*
4.0-Inch Screen
This implies that the device is either an iPhone 5 or a 5th generation iPod
Retina display is implicit
*/
type = iPhoneiPod4InchRetina;
}
else
{
/*
Device must be iPad 1/2/3/4/mini or iPhone 4/4S or iPhone 3G/3GS
*/
// Take a screenshot to determine if the device has retina display or not
UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, NO, 0.0);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *scaleCheckImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
{
/*
Device must be iPad 1/2/3/4/mini
*/
if(scaleCheckImage.scale == 1)
{
// iPad 1/2/mini (No Retina)
type = iPadNoRetina;
}
else if(scaleCheckImage.scale == 2)
{
// iPad 3/4 (Retina)
type = iPadRetina;
}
}
else
{
/*
Device must be iPhone 4/4S or iPhone 3G/3GS or iPod Touch 3rd Generation or iPod Touch 4th Generation
*/
if(scaleCheckImage.scale == 1)
{
// iPhone 3G/3GS or iPod Touch 3rd Generation (No Retina)
type = iPhoneiPod35InchNoRetina;
}
else if(scaleCheckImage.scale == 2)
{
// iPhone 4/4S or iPod Touch 4th Generation (Retina)
type = iPhoneiPod35InchRetina;
}
}
}
return type;
}
if(UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPad)
{
NSLog(@"All iPads");
}
else
{
else if (UI_USER_INTERFACE_IDIOM()== UIUserInterfaceIdiomPhone)
{
if( screenHeight > 480 && screenHeight < 667 )
{
NSLog(@"iPhone 5/5s/6");
}
else if ( screenHeight > 480 && screenHeight < 736 )
{
NSLog(@"Other iPhones Resizable");
}
else if ( screenHeight > 480 )
{
NSLog(@"iPhone 6 +");
}
else
{
NSLog(@"iPhone 4s and others");
}
}