Ⅰ iOS如何判斷是iOS11系統的宏定義
系統宏匯集
__FILE__
當前文件所在目錄
__DATE__
「替代文字」是一個含有編譯日期的字元串字面值,日期格式為「mm dd yyyy」(例如:「Mar 19 2006」)。如果日期小於10日,就在日的前面放一個空格符。NSLog(@"_DATE_=%s",__DATE__);
__FUNCTION__
當前函數名稱
__LINE__
當前語句在源文件中的行數
__TIME__
此字元串字面值包含編譯時間,格式為「hh:mm:ss」(範例:「08:00:59」)。
__STDC__
整數常量1,表示此編譯器遵循ISOC標准。
__STDC_VERSION__
如何實現復合C89整部1,則這個宏的值為19940SL;如果實現符合C99,則這個宏的值為199901L;否則數值是未定義
__STDC_EOBTED__
(C99)實現為宿主實現時為1,實現為獨立實現為0
__STDC_IEC_559__
(C99)浮點數實現復合IBC 60559標准時定義為1,否者數值是未定義
__STDC_IEC_559_COMPLEX__
(C99)復數運算實現復合IBC 60559標准時定義為1,否者數值是未定義
__STDC_ISO_10646__
(C99)定義為長整型常量,yyyymmL表示wchar_t值復合ISO 10646標准及其指定年月的修訂補充,否則數值未定義
Ⅱ 如何用宏區分ios工程和macos工程
像種需要用宏實現定義同工程
共同代碼部用宏判斷
Ⅲ 宏定義怎樣得到ios的系統版本
獲得IOS系統版本號
[[[UIDevice currentDevice] systemVersion] floatValue]
獲得硬體名稱
+ (NSString*)getMachine{
size_t size;
sysctlbyname("hw.machine", NULL, &size, NULL, 0);
char *name = malloc(size);
sysctlbyname("hw.machine", name, &size, NULL, 0);
NSString *machine = [NSString stringWithCString:name encoding:NSUTF8StringEncoding];
free(name);
if( [machine isEqualToString:@"i386"] || [machine isEqualToString:@"x86_64"] ) machine = @"ios_Simulator";
else if( [machine isEqualToString:@"iPhone1,1"] ) machine = @"iPhone_1G";
else if( [machine isEqualToString:@"iPhone1,2"] ) machine = @"iPhone_3G";
else if( [machine isEqualToString:@"iPhone2,1"] ) machine = @"iPhone_3GS";
else if( [machine isEqualToString:@"iPhone3,1"] ) machine = @"iPhone_4";
else if( [machine isEqualToString:@"iPod1,1"] ) machine = @"iPod_Touch_1G";
else if( [machine isEqualToString:@"iPod2,1"] ) machine = @"iPod_Touch_2G";
else if( [machine isEqualToString:@"iPod3,1"] ) machine = @"iPod_Touch_3G";
else if( [machine isEqualToString:@"iPod4,1"] ) machine = @"iPod_Touch_4G";
else if( [machine isEqualToString:@"iPad1,1"] ) machine = @"iPad_1";
else if( [machine isEqualToString:@"iPad2,1"] ) machine = @"iPad_2";
return machine;
}
Ⅳ 如何判斷當前iOS設備
開發當中幾種判斷當前iOS設備的實現方法,簡單粗暴的代碼段展現,希望對大家能有所幫助。
1.在程序中涉及到全屏的寬高的時候,初始化的時候,代碼中不要寫320和480
#define Screen_height [[UIScreen mainScreen] bounds].size.height #define Screen_width [[UIScreen mainScreen] bounds].size.width 2.使用宏定義方法判斷
#define iPhone5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : NO) if(iPhone5){ /*代碼操作*/ }else{ /*代碼操作*/ } if([ [ UIDevice currentDevice ] userInterfaceIdiom ] == UIUserInterfaceIdiomPhone ){ //IPhone設備 }else{ //ipad設備 }
網上還有一種方法:
+ (NSString*)deviceString { // 需要#import "sys/utsname.h" struct utsname systemInfo; uname(&systemInfo); NSString *deviceString = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding]; if ([deviceString isEqualToString:@"iPhone1,1"]) return @"iPhone 1G"; if ([deviceString isEqualToString:@"iPhone1,2"]) return @"iPhone 3G"; if ([deviceString isEqualToString:@"iPhone2,1"]) return @"iPhone 3GS"; if ([deviceString isEqualToString:@"iPhone3,1"]) return @"iPhone 4"; if ([deviceString isEqualToString:@"iPhone4,1"]) return @"iPhone 4S"; if ([deviceString isEqualToString:@"iPhone5,2"]) return @"iPhone 5"; if ([deviceString isEqualToString:@"iPhone3,2"]) return @"Verizon iPhone 4"; if ([deviceString isEqualToString:@"iPod1,1"]) return @"iPod Touch 1G"; if ([deviceString isEqualToString:@"iPod2,1"]) return @"iPod Touch 2G"; if ([deviceString isEqualToString:@"iPod3,1"]) return @"iPod Touch 3G"; if ([deviceString isEqualToString:@"iPod4,1"]) return @"iPod Touch 4G"; if ([deviceString isEqualToString:@"iPad1,1"]) return @"iPad"; if ([deviceString isEqualToString:@"iPad2,1"]) return @"iPad 2 (WiFi)"; if ([deviceString isEqualToString:@"iPad2,2"]) return @"iPad 2 (GSM)"; if ([deviceString isEqualToString:@"iPad2,3"]) return @"iPad 2 (CDMA)"; if ([deviceString isEqualToString:@"i386"]) return @"Simulator"; if ([deviceString isEqualToString:@"x86_64"]) return @"Simulator"; NSLog(@"NOTE: Unknown device type: %@", deviceString); return deviceString; }
轉載