No Description

UIDevice+YLDevice.h 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. //
  2. // UIDevice+YLDevice.h
  3. // YoungCatogory
  4. //
  5. // Created by kuxuan on 2017/7/17.
  6. // Copyright © 2017年 kuxuan. All rights reserved.
  7. //
  8. #import <UIKit/UIKit.h>
  9. #import <AdSupport/AdSupport.h>
  10. @interface UIDevice (YLDevice)
  11. /**
  12. * Get the iOS version string
  13. */
  14. #define IOS_VERSION [UIDevice currentDevice].systemVersion
  15. /**
  16. * Macros to compare system versions
  17. *
  18. * @param v Version, like @"9.0"
  19. *
  20. * @return Returns a BOOL
  21. */
  22. #define SYSTEM_VERSION_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame)
  23. #define SYSTEM_VERSION_GREATER_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)
  24. #define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
  25. #define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
  26. #define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)
  27. /**
  28. * Macros that returns if the iOS version is greater or equal to choosed one
  29. *
  30. * @return Returns a BOOL
  31. */
  32. #define IS_IOS_5_OR_LATER ([[[UIDevice currentDevice] systemVersion] floatValue] >= 5.0)
  33. #define IS_IOS_6_OR_LATER ([[[UIDevice currentDevice] systemVersion] floatValue] >= 6.0)
  34. #define IS_IOS_7_OR_LATER ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0)
  35. #define IS_IOS_8_OR_LATER ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
  36. #define IS_IOS_9_OR_LATER ([[[UIDevice currentDevice] systemVersion] floatValue] >= 9.0)
  37. /**
  38. * Returns the device platform string
  39. * Example: "iPhone7,2"
  40. *
  41. * @return Returns the device platform string
  42. */
  43. + (NSString * _Nonnull)devicePlatform;
  44. /**
  45. * Returns the user-friendly device platform string
  46. * Example: "iPad Air (Cellular)"
  47. *
  48. * @return Returns the user-friendly device platform string
  49. */
  50. + (NSString * _Nonnull)devicePlatformString;
  51. /**
  52. * Returns current resolution string
  53. * Example: "320x480"
  54. *
  55. * @return Returns current resolution string
  56. */
  57. + (NSString * _Nonnull)currentResolution;
  58. /**
  59. * Check if the current device is an iPad
  60. *
  61. * @return Returns YES if it's an iPad, NO if not
  62. */
  63. + (BOOL)isiPad;
  64. /**
  65. * Check if the current device is an iPhone
  66. *
  67. * @return Returns YES if it's an iPhone, NO if not
  68. */
  69. + (BOOL)isiPhone;
  70. /**
  71. * Check if the current device is an iPod
  72. *
  73. * @return Returns YES if it's an iPod, NO if not
  74. */
  75. + (BOOL)isiPod;
  76. /**
  77. * Check if the current device is an Apple TV
  78. *
  79. * @return Returns YES if it's an Apple TV, NO if not
  80. */
  81. + (BOOL)isAppleTV;
  82. /**
  83. * Check if the current device is an Apple Watch
  84. *
  85. * @return Returns YES if it's an Apple Watch, NO if not
  86. */
  87. + (BOOL)isAppleWatch;
  88. /**
  89. * Check if the current device is the simulator
  90. *
  91. * @return Returns YES if it's the simulator, NO if not
  92. */
  93. + (BOOL)isSimulator;
  94. /**
  95. * Returns the iOS version without the subversion
  96. * Example: 7
  97. *
  98. * @return Returns the iOS version
  99. */
  100. + (NSInteger)iOSVersion;
  101. /**
  102. * Returns the current device CPU frequency
  103. *
  104. * @return Returns the current device CPU frequency
  105. */
  106. + (NSUInteger)cpuFrequency;
  107. /**
  108. * Returns the current device BUS frequency
  109. *
  110. * @return Returns the current device BUS frequency
  111. */
  112. + (NSUInteger)busFrequency;
  113. /**
  114. * Returns the current device RAM size
  115. *
  116. * @return Returns the current device RAM size
  117. */
  118. + (NSUInteger)ramSize;
  119. /**
  120. * Returns the current device CPU number
  121. *
  122. * @return Returns the current device CPU number
  123. */
  124. + (NSUInteger)cpuNumber;
  125. /**
  126. * Returns the current device total memory
  127. *
  128. * @return Returns the current device total memory
  129. //手机总磁盘
  130. */
  131. + (NSUInteger)totalMemory;
  132. /**
  133. * Returns the current device non-kernel memory
  134. *
  135. * @return Returns the current device non-kernel memory
  136. */
  137. + (NSUInteger)userMemory;
  138. /**
  139. * Returns the current device total disk space
  140. *
  141. * @return Returns the current device total disk space
  142. */
  143. + (NSNumber * _Nonnull)totalDiskSpace;
  144. /**
  145. * Returns the current device free disk space
  146. *
  147. * @return Returns the current device free disk space
  148. */
  149. + (NSNumber * _Nonnull)freeDiskSpace;
  150. /**
  151. * Generate an unique identifier and store it into standardUserDefaults
  152. *
  153. * @return Returns a unique identifier as a NSString
  154. */
  155. + (NSString * _Nonnull)uniqueIdentifier;
  156. /**
  157. * Generate an idfa and store it into standardUserDefaults
  158. *
  159. * @return Returns an idfa as a NSString
  160. */
  161. + (NSString * _Nonnull)idfaString;
  162. /**
  163. * Save the unique identifier or update it if there is and it is changed.
  164. * Is useful for push notification to know if the unique identifier has changed and needs to be send to server
  165. *
  166. * @param uniqueIdentifier The unique identifier to save or update if needed. (Must be NSData or NSString)
  167. * @param block The execution block that know if the unique identifier is valid and has to be updated. You have to handle the case if it is valid and the update is needed or not
  168. */
  169. + (void)updateUniqueIdentifier:(NSObject * _Nonnull)uniqueIdentifier block:(void (^ _Nullable)(BOOL isValid, BOOL hasToUpdateUniqueIdentifier, NSString * _Nullable oldUUID))block;
  170. //数据转换
  171. +(NSString *)fileSizeToString:(NSNumber *)fileSize;
  172. @end