作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我已经使用此代码来检测设备是否为 iPhone 5 以设置适当的 UI。
( fabs( ( double )[ [ UIScreen mainScreen ] bounds ].size.height - ( double )568 ) < DBL_EPSILON )
最佳答案
嗯,一开始你也确实把 iPhone5S 认成了 iPhone 5,这不一样。
我宁愿使用设备名称,因为您的宏可以随心所欲地扩展。
#import <sys/utsname.h>
NSString* deviceName()
{
struct utsname systemInfo;
uname(&systemInfo);
NSString *result = [NSString stringWithCString:systemInfo.machine
encoding:NSUTF8StringEncoding];
return result;
}
#define isIPhone5 [deviceName() rangeOfString:@"iPhone5,"].location != NSNotFound
#define isIPhone5S [deviceName() rangeOfString:@"iPhone6,"].location != NSNotFound
/*
@"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
@"iPod5,1" on iPod Touch Fifth 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 3rd Generation iPad
@"iPad3,2": on iPad 3(GSM+CDMA)
@"iPad3,3": on iPad 3(GSM)
@"iPad3,4": on iPad 4(WiFi)
@"iPad3,5": on iPad 4(GSM)
@"iPad3,6": on iPad 4(GSM+CDMA)
@"iPhone3,1" on iPhone 4
@"iPhone4,1" on iPhone 4S
@"iPhone5,1" on iPhone 5
@"iPad3,4" on 4th Generation iPad
@"iPad2,5" on iPad Mini
@"iPhone5,1" on iPhone 5(GSM)
@"iPhone5,2" on iPhone 5(GSM+CDMA)
@"iPhone5,3 on iPhone 5c(GSM)
@"iPhone5,4" on iPhone 5c(GSM+CDMA)
@"iPhone6,1" on iPhone 5s(GSM)
@"iPhone6,2" on iPhone 5s(GSM+CDMA)
*/
NSString* deviceName();
#import "Helperfunctions.h"
#import <sys/utsname.h>
NSString* deviceName()
{
struct utsname systemInfo;
uname(&systemInfo);
NSString *result = [NSString stringWithCString:systemInfo.machine
encoding:NSUTF8StringEncoding];
return result;
}
//
// Prefix header
//
// The contents of this file are implicitly included at the beginning of every source file.
//
#import <Availability.h>
#ifndef __IPHONE_5_0
#warning "This project uses features only available in iOS SDK 5.0 and later."
#endif
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import "Helperfunctions.h"
#define isIPhone5 [deviceName() rangeOfString:@"iPhone5,"].location != NSNotFound
#define isIPhone5S [deviceName() rangeOfString:@"iPhone6,"].location != NSNotFound
#endif
关于ios - 即使在 iPhone 5 上运行 IS IPHONE_5 也会返回 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22980213/
我是一名优秀的程序员,十分优秀!