XTSystem.m 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. //
  2. // XTSystem.m
  3. // XTFramework
  4. //
  5. // Created by Qing Xiubin on 13-8-15.
  6. // Copyright (c) 2013年 XT. All rights reserved.
  7. //
  8. #import "XTSystem.h"
  9. #include <sys/types.h>
  10. #include <sys/sysctl.h>
  11. @implementation XTSystem
  12. + (NSString *)osVersion{
  13. #if (TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR)
  14. return [NSString stringWithFormat:@"%@ %@", [UIDevice currentDevice].systemName, [UIDevice currentDevice].systemVersion];
  15. #else
  16. return nil;
  17. #endif
  18. }
  19. + (NSString *)appVersion{
  20. #if (TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR || TARGET_OS_MAC)
  21. return [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
  22. #else
  23. return nil;
  24. #endif
  25. }
  26. + (NSString *)appBuild{
  27. #if (TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR)
  28. return [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"];
  29. #else
  30. return nil;
  31. #endif
  32. }
  33. + (NSString *)appIdentifier{
  34. #if (TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR)
  35. return [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleIdentifier"];
  36. #else
  37. return nil;
  38. #endif
  39. }
  40. + (NSString *)deviceModel{
  41. #if (TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR)
  42. return [[UIDevice currentDevice] model];
  43. #else
  44. return nil;
  45. #endif
  46. }
  47. + (NSString *)deviceUUID{
  48. #if (TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR || TARGET_OS_MAC)
  49. // if (IOS6_OR_LATER) {
  50. // return [[[UIDevice currentDevice] identifierForVendor] UUIDString];
  51. // } else {
  52. //
  53. // }
  54. return [NSString mechineID];
  55. #else
  56. return nil;
  57. #endif
  58. }
  59. + (CGFloat)statuBarHeight{
  60. if (IOS7_OR_LATER) {
  61. return 20;
  62. }else{
  63. return 0;
  64. }
  65. }
  66. + (CGFloat)navBarHeight{
  67. return 44;
  68. }
  69. #if (TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR)
  70. static const char * __jb_app = NULL;
  71. #endif
  72. //+ (BOOL)isJailBroken NS_AVAILABLE_IOS(4_0){
  73. //#if (TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR)
  74. // static const char * __jb_apps[] ={
  75. // "/Application/Cydia.app",
  76. // "/Application/limera1n.app",
  77. // "/Application/greenpois0n.app",
  78. // "/Application/blackra1n.app",
  79. // "/Application/blacksn0w.app",
  80. // "/Application/redsn0w.app",
  81. // NULL
  82. // };
  83. //
  84. // __jb_app = NULL;
  85. //
  86. // // method 1
  87. // for ( int i = 0; __jb_apps[i]; ++i ){
  88. // if ( [[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithUTF8String:__jb_apps[i]]] )
  89. // {
  90. // __jb_app = __jb_apps[i];
  91. // return YES;
  92. // }
  93. // }
  94. //
  95. // // method 2
  96. // if ( [[NSFileManager defaultManager] fileExistsAtPath:@"/private/var/lib/apt/"] ){
  97. // return YES;
  98. // }
  99. //
  100. // // method 3
  101. // if ( 0 == system("ls") ){
  102. // return YES;
  103. // }
  104. //#endif
  105. //
  106. // return NO;
  107. //}
  108. + (NSString *)jailBreaker NS_AVAILABLE_IOS(4_0){
  109. #if (TARGET_OS_IPHONE)
  110. if ( __jb_app ){
  111. return [NSString stringWithUTF8String:__jb_app];
  112. }
  113. #endif
  114. return @"";
  115. }
  116. + (BOOL)isDevicePhone{
  117. #if (TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR)
  118. NSString * deviceType = [UIDevice currentDevice].model;
  119. if ( [deviceType rangeOfString:@"iPhone" options:NSCaseInsensitiveSearch].length > 0 ||
  120. [deviceType rangeOfString:@"iPod" options:NSCaseInsensitiveSearch].length > 0 ||
  121. [deviceType rangeOfString:@"iTouch" options:NSCaseInsensitiveSearch].length > 0 ){
  122. return YES;
  123. }
  124. #endif
  125. return NO;
  126. }
  127. + (BOOL)isDevicePad{
  128. #if (TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR)
  129. NSString * deviceType = [UIDevice currentDevice].model;
  130. if ( [deviceType rangeOfString:@"iPad" options:NSCaseInsensitiveSearch].length > 0 ){
  131. return YES;
  132. }
  133. #endif
  134. return NO;
  135. }
  136. + (BOOL)isPhone35{
  137. #if (TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR)
  138. return [XTSystem isScreenSize:CGSizeMake(320, 480)];
  139. #else
  140. return NO;
  141. #endif
  142. }
  143. + (BOOL)isPhoneRetina35{
  144. #if (TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR)
  145. return [XTSystem isScreenSize:CGSizeMake(640, 960)];
  146. #else
  147. return NO;
  148. #endif
  149. }
  150. + (BOOL)isPhoneRetina4{
  151. #if (TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR)
  152. return [XTSystem isScreenSize:CGSizeMake(640, 1136)];
  153. #else
  154. return NO;
  155. #endif
  156. }
  157. + (BOOL)isPhoneRetina6{
  158. #if (TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR)
  159. return [XTSystem isScreenSize:CGSizeMake(750, 1334)];
  160. #else
  161. return NO;
  162. #endif
  163. }
  164. + (BOOL)isPhoneRetina6Plus{
  165. #if (TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR)
  166. return [XTSystem isScreenSize:CGSizeMake(1242, 2208)];
  167. #else
  168. return NO;
  169. #endif
  170. }
  171. + (BOOL)isPhoneRetinaX{
  172. #if (TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR)
  173. return [XTSystem isScreenSize:CGSizeMake(1125, 2436)];
  174. #else
  175. return NO;
  176. #endif
  177. }
  178. + (BOOL)isPad{
  179. #if (TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR)
  180. return [XTSystem isScreenSize:CGSizeMake(768, 1024)];
  181. #else
  182. return NO;
  183. #endif
  184. }
  185. + (BOOL)isPadRetina{
  186. #if (TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR)
  187. return [XTSystem isScreenSize:CGSizeMake(1536, 2048)];
  188. #else
  189. return NO;
  190. #endif
  191. }
  192. + (BOOL)isScreenSize:(CGSize)size{
  193. #if (TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR)
  194. if ( [UIScreen instancesRespondToSelector:@selector(currentMode)] ){
  195. CGSize screenSize = [UIScreen mainScreen].currentMode.size;
  196. CGSize size2 = CGSizeMake( size.height, size.width );
  197. if ( CGSizeEqualToSize(size, screenSize) || CGSizeEqualToSize(size2, screenSize) ){
  198. return YES;
  199. }
  200. }
  201. return NO;
  202. #else
  203. return NO;
  204. #endif
  205. }
  206. //获得设备型号
  207. + (NSString *)getCurrentDeviceModel
  208. {
  209. int mib[2];
  210. size_t len;
  211. char *machine;
  212. mib[0] = CTL_HW;
  213. mib[1] = HW_MACHINE;
  214. sysctl(mib, 2, NULL, &len, NULL, 0);
  215. machine = malloc(len);
  216. sysctl(mib, 2, machine, &len, NULL, 0);
  217. NSString *platform = [NSString stringWithCString:machine encoding:NSASCIIStringEncoding];
  218. free(machine);
  219. if ([platform isEqualToString:@"iPhone1,1"]) return @"iPhone 2G (A1203)";
  220. if ([platform isEqualToString:@"iPhone1,2"]) return @"iPhone 3G (A1241/A1324)";
  221. if ([platform isEqualToString:@"iPhone2,1"]) return @"iPhone 3GS (A1303/A1325)";
  222. if ([platform isEqualToString:@"iPhone3,1"]) return @"iPhone 4 (A1332)";
  223. if ([platform isEqualToString:@"iPhone3,2"]) return @"iPhone 4 (A1332)";
  224. if ([platform isEqualToString:@"iPhone3,3"]) return @"iPhone 4 (A1349)";
  225. if ([platform isEqualToString:@"iPhone4,1"]) return @"iPhone 4S (A1387/A1431)";
  226. if ([platform isEqualToString:@"iPhone5,1"]) return @"iPhone 5 (A1428)";
  227. if ([platform isEqualToString:@"iPhone5,2"]) return @"iPhone 5 (A1429/A1442)";
  228. if ([platform isEqualToString:@"iPhone5,3"]) return @"iPhone 5c (A1456/A1532)";
  229. if ([platform isEqualToString:@"iPhone5,4"]) return @"iPhone 5c (A1507/A1516/A1526/A1529)";
  230. if ([platform isEqualToString:@"iPhone6,1"]) return @"iPhone 5s (A1453/A1533)";
  231. if ([platform isEqualToString:@"iPhone6,2"]) return @"iPhone 5s (A1457/A1518/A1528/A1530)";
  232. if ([platform isEqualToString:@"iPhone7,1"]) return @"iPhone 6 Plus (A1522/A1524)";
  233. if ([platform isEqualToString:@"iPhone7,2"]) return @"iPhone 6 (A1549/A1586)";
  234. if ([platform isEqualToString:@"iPod1,1"]) return @"iPod Touch 1G (A1213)";
  235. if ([platform isEqualToString:@"iPod2,1"]) return @"iPod Touch 2G (A1288)";
  236. if ([platform isEqualToString:@"iPod3,1"]) return @"iPod Touch 3G (A1318)";
  237. if ([platform isEqualToString:@"iPod4,1"]) return @"iPod Touch 4G (A1367)";
  238. if ([platform isEqualToString:@"iPod5,1"]) return @"iPod Touch 5G (A1421/A1509)";
  239. if ([platform isEqualToString:@"iPad1,1"]) return @"iPad 1G (A1219/A1337)";
  240. if ([platform isEqualToString:@"iPad2,1"]) return @"iPad 2 (A1395)";
  241. if ([platform isEqualToString:@"iPad2,2"]) return @"iPad 2 (A1396)";
  242. if ([platform isEqualToString:@"iPad2,3"]) return @"iPad 2 (A1397)";
  243. if ([platform isEqualToString:@"iPad2,4"]) return @"iPad 2 (A1395+New Chip)";
  244. if ([platform isEqualToString:@"iPad2,5"]) return @"iPad Mini 1G (A1432)";
  245. if ([platform isEqualToString:@"iPad2,6"]) return @"iPad Mini 1G (A1454)";
  246. if ([platform isEqualToString:@"iPad2,7"]) return @"iPad Mini 1G (A1455)";
  247. if ([platform isEqualToString:@"iPad3,1"]) return @"iPad 3 (A1416)";
  248. if ([platform isEqualToString:@"iPad3,2"]) return @"iPad 3 (A1403)";
  249. if ([platform isEqualToString:@"iPad3,3"]) return @"iPad 3 (A1430)";
  250. if ([platform isEqualToString:@"iPad3,4"]) return @"iPad 4 (A1458)";
  251. if ([platform isEqualToString:@"iPad3,5"]) return @"iPad 4 (A1459)";
  252. if ([platform isEqualToString:@"iPad3,6"]) return @"iPad 4 (A1460)";
  253. if ([platform isEqualToString:@"iPad4,1"]) return @"iPad Air (A1474)";
  254. if ([platform isEqualToString:@"iPad4,2"]) return @"iPad Air (A1475)";
  255. if ([platform isEqualToString:@"iPad4,3"]) return @"iPad Air (A1476)";
  256. if ([platform isEqualToString:@"iPad4,4"]) return @"iPad Mini 2G (A1489)";
  257. if ([platform isEqualToString:@"iPad4,5"]) return @"iPad Mini 2G (A1490)";
  258. if ([platform isEqualToString:@"iPad4,6"]) return @"iPad Mini 2G (A1491)";
  259. if ([platform isEqualToString:@"i386"]) return @"iPhone Simulator";
  260. if ([platform isEqualToString:@"x86_64"]) return @"iPhone Simulator";
  261. return platform;
  262. }
  263. @end