RQMacros.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. //
  2. // RQMacros.h
  3. // RQCommon
  4. //
  5. // Created by 张嵘 on 2018/11/13.
  6. // Copyright © 2018 张嵘. All rights reserved.
  7. // APP所有的宏常量 仅限于 #define
  8. #ifndef RQMacros_h
  9. #define RQMacros_h
  10. /// 存储应用版本的key
  11. #define RQApplicationVersionKey @"RQApplicationVersionKey"
  12. /// 应用名称
  13. #define RQ_APP_NAME ([[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleName"])
  14. /// 应用版本号
  15. #define RQ_APP_VERSION ([[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"])
  16. /// 应用build
  17. #define RQ_APP_BUILD ([[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"])
  18. //友盟
  19. #define UM_APPKEY @"64828a40e31d6071ec4d2ac7"
  20. // 输出日志 (格式: [时间] [哪个方法] [哪行] [输出内容])
  21. #ifdef DEBUG
  22. #define NSLog(format, ...) printf("\n[%s] %s [第%d行] 💕 %s\n", __TIME__, __FUNCTION__, __LINE__, [[NSString stringWithFormat:format, ##__VA_ARGS__] UTF8String]);
  23. #else
  24. #define NSLog(format, ...)
  25. #endif
  26. // 打印方法
  27. #define RQLogFunc NSLog(@"%s", __func__)
  28. // 打印请求错误信息
  29. #define RQLogError(error) NSLog(@"Error: %@", error)
  30. // 销毁打印
  31. #define RQDealloc NSLog(@"\n =========+++ %@ 销毁了 +++======== \n",[self class])
  32. #define RQLogLastError(db) NSLog(@"lastError: %@, lastErrorCode: %d, lastErrorMessage: %@", [db lastError], [db lastErrorCode], [db lastErrorMessage]);
  33. /// 类型相关
  34. #define RQ_IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
  35. #define RQ_IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
  36. #define RQ_IS_RETINA ([[UIScreen mainScreen] scale] >= 2.0)
  37. /// 屏幕尺寸相关
  38. #define RQ_SCREEN_WIDTH ([[UIScreen mainScreen] bounds].size.width)
  39. #define RQ_SCREEN_HEIGHT ([[UIScreen mainScreen] bounds].size.height)
  40. #define RQ_SCREEN_BOUNDS ([[UIScreen mainScreen] bounds])
  41. #define RQ_SCREEN_MAX_LENGTH (MAX(RQ_SCREEN_WIDTH, RQ_SCREEN_HEIGHT))
  42. #define RQ_SCREEN_MIN_LENGTH (MIN(RQ_SCREEN_WIDTH, RQ_SCREEN_HEIGHT))
  43. #define RQ_FIT_VERTICAL(float) (float / 667.f) * RQ_SCREEN_HEIGHT
  44. #define RQ_FIT_HORIZONTAL(float) (float / 375.f) * RQ_SCREEN_WIDTH
  45. /// 手机类型相关
  46. #define RQ_IS_IPHONE_4_OR_LESS (RQ_IS_IPHONE && RQ_SCREEN_MAX_LENGTH < 568.0)
  47. ///判断iPhone4系列
  48. #define RQ_IS_IPHONE_4 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 960), [[UIScreen mainScreen] currentMode].size) && !RQ_IS_IPAD : NO)
  49. ///判断iPhone5系列
  50. #define RQ_IS_IPHONE_5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) && !RQ_IS_IPAD : NO)
  51. ///判断iPhone6系列
  52. #define RQ_IS_IPHONE_6 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(750, 1334), [[UIScreen mainScreen] currentMode].size) && !RQ_IS_IPAD : NO)
  53. ///判断iphone6+系列
  54. #define RQ_IS_IPHONE_6P ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1242, 2208), [[UIScreen mainScreen] currentMode].size) && !RQ_IS_IPAD : NO)
  55. ///判断iPhoneX
  56. #define RQ_IS_IPHONE_X ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1125, 2436), [[UIScreen mainScreen] currentMode].size) && !RQ_IS_IPAD : NO)
  57. ///判断iPHoneXr
  58. #define RQ_IS_IPHONE_XR ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(828, 1792), [[UIScreen mainScreen] currentMode].size) && !RQ_IS_IPAD : NO)
  59. ///判断iPhoneXs
  60. #define RQ_IS_IPHONE_XS ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1125, 2436), [[UIScreen mainScreen] currentMode].size) && !RQ_IS_IPAD : NO)
  61. ///判断iPhoneXs Max
  62. #define RQ_IS_IPHONE_XS_MAX ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1242, 2688), [[UIScreen mainScreen] currentMode].size) && !RQ_IS_IPAD : NO)
  63. ///判断iPhone12_Mini
  64. #define RQ_IS_IPHONE_iPhone12_Mini ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1080, 2340), [[UIScreen mainScreen] currentMode].size) && !RQ_IS_IPAD : NO)
  65. ///判断iPhone12 | 12Pro
  66. #define RQ_IS_IPHONE_iPhone12 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1170, 2532), [[UIScreen mainScreen] currentMode].size) && !RQ_IS_IPAD : NO)
  67. ///判断iPhone12 Pro Max
  68. #define RQ_IS_IPHONE_iPhone12_ProMax ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1284, 2778), [[UIScreen mainScreen] currentMode].size) && !RQ_IS_IPAD : NO)
  69. ///x系列
  70. #define RQ_IS_IPHONE_IPhoneX_All (RQ_IS_IPHONE_X || RQ_IS_IPHONE_XR || RQ_IS_IPHONE_XS || RQ_IS_IPHONE_XS_MAX || RQ_IS_IPHONE_iPhone12_Mini || RQ_IS_IPHONE_iPhone12 || RQ_IS_IPHONE_iPhone12_ProMax)
  71. /// 常见的高度
  72. #define RQ_APPLICATION_COMMON_HEIGHT_92 92.0f
  73. #define RQ_APPLICATION_COMMON_HEIGHT_91 91.0f
  74. #define RQ_APPLICATION_COMMON_HEIGHT_88 88.0f
  75. #define RQ_APPLICATION_COMMON_HEIGHT_83 83.0f
  76. #define RQ_APPLICATION_COMMON_HEIGHT_64 64.0f
  77. #define RQ_APPLICATION_COMMON_HEIGHT_51 51.0f
  78. #define RQ_APPLICATION_COMMON_HEIGHT_49 49.0f
  79. #define RQ_APPLICATION_COMMON_HEIGHT_44 44.0f
  80. #define RQ_APPLICATION_COMMON_HEIGHT_34 34.0f
  81. #define RQ_APPLICATION_COMMON_HEIGHT_20 20.0f
  82. #define RQ_APPLICATION_COMMON_HEIGHT_16 16.0f
  83. #define RQ_APPLICATION_COMMON_HEIGHT_12 12.0f
  84. #define RQ_APPLICATION_COMMON_HEIGHT_8 8.0f
  85. #define RQ_APPLICATION_COMMON_HEIGHT_0 0.0f
  86. /// 导航栏高度
  87. #define RQ_APPLICATION_NAV_BAR_HEIGHT RQ_APPLICATION_COMMON_HEIGHT_44
  88. /// tabBar高度
  89. #define RQ_APPLICATION_TAB_BAR_HEIGHT RQ_APPLICATION_COMMON_HEIGHT_49 + RQ_APPLICATION_SAFEAREA_BOTTOM_HEIGHT
  90. /// 状态栏高度
  91. #define RQ_APPLICATION_STATUS_BAR_HEIGHT \
  92. ({CGFloat statusBarHeight = 0.0;\
  93. if (@available(iOS 11.0, *)) {\
  94. statusBarHeight = [UIApplication sharedApplication].windows.firstObject.safeAreaInsets.top;\
  95. } else { \
  96. statusBarHeight = 20;\
  97. }\
  98. (statusBarHeight);\
  99. })
  100. /// 底部安全区域高度
  101. //#define RQ_APPLICATION_SAFEAREA_BOTTOM_HEIGHT (RQ_IS_IPHONE_IPhoneX_All ? RQ_APPLICATION_COMMON_HEIGHT_34 : RQ_APPLICATION_COMMON_HEIGHT_0)
  102. #define RQ_APPLICATION_SAFEAREA_BOTTOM_HEIGHT \
  103. ({CGFloat safeBottomHeight = 0.0;\
  104. if (@available(iOS 11.0, *)) {\
  105. safeBottomHeight = [UIApplication sharedApplication].windows.firstObject.safeAreaInsets.bottom;\
  106. } else { \
  107. safeBottomHeight = 0;\
  108. }\
  109. (safeBottomHeight);\
  110. })
  111. #define RQ_WIDTH(WIDTH) WIDTH * [UIScreen mainScreen].bounds.size.width/375.0
  112. #define RQWeak(type) __weak typeof(type) weak##type = type
  113. #define WeakSelf(weakSelf) __weak __typeof(&*self) weakSelf = self;
  114. #define StrongSelf(strongSelf) __strong __typeof(&*self) strongSelf = weakSelf;
  115. ///------
  116. /// iOS Version
  117. ///------
  118. #define RQIOSVersion ([[[UIDevice currentDevice] systemVersion] floatValue])
  119. #define RQ_iOS7_VERSTION_LATER ([UIDevice currentDevice].systemVersion.floatValue >= 7.0)
  120. #define RQ_iOS8_VERSTION_LATER ([UIDevice currentDevice].systemVersion.floatValue >= 8.0)
  121. #define RQ_iOS9_VERSTION_LATER ([UIDevice currentDevice].systemVersion.floatValue >= 9.0)
  122. #define RQ_iOS10_VERSTION_LATER ([UIDevice currentDevice].systemVersion.floatValue >= 10.0)
  123. #define RQ_iOS11_VERSTION_LATER ([UIDevice currentDevice].systemVersion.floatValue >= 11.0)
  124. #define RQ_iOS12_VERSTION_LATER ([UIDevice currentDevice].systemVersion.floatValue >= 12.0)
  125. #define RQ_iOS13_VERSTION_LATER ([UIDevice currentDevice].systemVersion.floatValue >= 13.0)
  126. #define RQ_iOS14_VERSTION_LATER ([UIDevice currentDevice].systemVersion.floatValue >= 14.0)
  127. #define RQ_iOS15_VERSTION_LATER ([UIDevice currentDevice].systemVersion.floatValue >= 15.0)
  128. #define RQ_SYSTEM_VERSION_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame)
  129. #define RQ_SYSTEM_VERSION_GREATER_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)
  130. #define RQ_SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
  131. #define RQ_SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
  132. #define RQ_SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)
  133. // KVO获取监听对象的属性 有自动提示
  134. // 宏里面的#,会自动把后面的参数变成c语言的字符串
  135. #define RQKeyPath(objc,keyPath) @(((void)objc.keyPath ,#keyPath))
  136. // 颜色
  137. #define RQColor(r, g, b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1.0]
  138. // 颜色+透明度
  139. #define RQColorAlpha(r, g, b, a) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:a]
  140. // 随机色
  141. #define RQRandomColor RQColor(arc4random_uniform(256), arc4random_uniform(256), arc4random_uniform(256))
  142. // 根据rgbValue获取对应的颜色
  143. #define RQColorFromRGB(__rgbValue) [UIColor colorWithRed:((float)((__rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((__rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(__rgbValue & 0xFF))/255.0 alpha:1.0]
  144. #define RQColorFromRGBAlpha(rgbValue, a) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:(a)]
  145. // AppCaches 文件夹路径
  146. #define RQCachesDirectory [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject]
  147. // App DocumentDirectory 文件夹路径
  148. #define RQDocumentDirectory [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES) lastObject]
  149. // 系统放大倍数
  150. #define RQScale [[UIScreen mainScreen] scale]
  151. // 设置图片
  152. #define RQImageNamed(__imageName) [UIImage imageNamed:__imageName]
  153. /// 根据hex 获取颜色
  154. #define RQColorFromHexString(__hexString__) ([UIColor qmui_colorWithHexString:__hexString__])
  155. // 通知中心
  156. #define RQNotificationCenter [NSNotificationCenter defaultCenter]
  157. /// 全局细下滑线颜色 以及分割线颜色
  158. #define RQGlobalBottomLineColor [UIColor qmui_colorWithHexString:@"#D9D9D9"]
  159. // 是否为空对象
  160. #define RQObjectIsNil(__object) ((nil == __object) || [__object isKindOfClass:[NSNull class]])
  161. // 字符串为空
  162. #define RQStringIsEmpty(__string) ((__string.length == 0) || RQObjectIsNil(__string))
  163. // 字符串不为空
  164. #define RQStringIsNotEmpty(__string) (!RQStringIsEmpty(__string))
  165. // 数组为空
  166. #define RQArrayIsEmpty(__array) ((RQObjectIsNil(__array)) || (__array.count==0))
  167. /// 适配iPhone X + iOS 11
  168. #define RQAdjustsScrollViewInsets_Never(__scrollView)\
  169. do {\
  170. _Pragma("clang diagnostic push")\
  171. _Pragma("clang diagnostic ignored \"-Warc-performSelector-leaks\"")\
  172. if ([__scrollView respondsToSelector:NSSelectorFromString(@"setContentInsetAdjustmentBehavior:")]) {\
  173. NSMethodSignature *signature = [UIScrollView instanceMethodSignatureForSelector:@selector(setContentInsetAdjustmentBehavior:)];\
  174. NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature];\
  175. NSInteger argument = 2;\
  176. invocation.target = __scrollView;\
  177. invocation.selector = @selector(setContentInsetAdjustmentBehavior:);\
  178. [invocation setArgument:&argument atIndex:2];\
  179. [invocation retainArguments];\
  180. [invocation invoke];\
  181. }\
  182. _Pragma("clang diagnostic pop")\
  183. } while (0)
  184. //// -------------------- 下面是公共配置 --------------------
  185. /// 微信项目重要数据备份的文件夹名称(Documents/WeChatDoc)利用NSFileManager来访问
  186. #define RQ_WECHAT_DOC_NAME @"WeChatDoc"
  187. /// 微信项目轻量数据数据备份的文件夹(Library/Caches/WeChatCache)利用NSFileManager来访问
  188. #define RQ_WECHAT_CACHE_NAME @"WeChatCache"
  189. /// AppDelegate
  190. #define RQSharedAppDelegate ((AppDelegate *)[UIApplication sharedApplication].delegate)
  191. //// 整个应用的主题配置(颜色+字体)MAIN 代表全局都可以修改 使用前须知
  192. #define RQ_MAIN_NAVIGATIONBAR_BACKGROUNDCOLOR_1 [UIColor colorWithRed:.1 green:.1 blue:.1 alpha:0.65]
  193. #define RQ_MAIN_NAVIGATIONBAR_BACKGROUNDCOLOR_2 [UIColor qmui_colorWithHexString:@"#EFEFF4"]
  194. #define RQ_MAIN_NAVIGATIONBAR_BACKGROUNDCOLOR_3 [UIColor qmui_colorWithHexString:@"#F3F3F3"]
  195. #define RQ_MAIN_NAVIGATIONBAR_BACKGROUNDCOLOR_4 [UIColor qmui_colorWithHexString:@"#E6A863"]
  196. /// 全局青色 tintColor
  197. #define RQ_MAIN_TINTCOLOR [UIColor qmui_colorWithHexString:@"#498EF5"]
  198. #define RQ_MAIN_COLOR [UIColor qmui_colorWithHexString:@"#498EF5"]
  199. /// 整个应用的视图的背景色 BackgroundColor
  200. #define RQ_MAIN_BACKGROUNDCOLOR [UIColor qmui_colorWithHexString:@"#FFFFFF"]
  201. #define RQ_LIST_BACKGROUNDCOLOR [UIColor qmui_colorWithHexString:@"#F2F3F5"]
  202. #define RQ_MAIN_ITEM_BACKGROUNDCOLOR [UIColor qmui_colorWithHexString:@"#EBEBEB"]
  203. #define RQ_BACKGROUNDCOLOR_1 [UIColor qmui_colorWithHexString:@"#F0F3F7"]
  204. #define RQ_BACKGROUNDCOLOR_2 [UIColor qmui_colorWithHexString:@"#BFD8FF"]
  205. #define RQ_BACKGROUNDCOLOR_3 [UIColor qmui_colorWithHexString:@"#B8C0CC"]
  206. /// 整个应用的分割线颜色
  207. #define RQ_MAIN_LINE_COLOR_1 [UIColor qmui_colorWithHexString:@"#E8E8E8"]
  208. /// 文字颜色
  209. /// #0A1A33
  210. #define RQ_MAIN_TEXT_COLOR_1 [UIColor qmui_colorWithHexString:@"#0A1A33"]
  211. /// #8A9099
  212. #define RQ_MAIN_TEXT_COLOR_2 [UIColor qmui_colorWithHexString:@"#8A9099"]
  213. /// #5C6066
  214. #define RQ_MAIN_TEXT_COLOR_3 [UIColor qmui_colorWithHexString:@"#5C6066"]
  215. /// #01C18D
  216. #define RQ_MAIN_TEXT_COLOR_4 [UIColor qmui_colorWithHexString:@"#01C18D"]
  217. /// #707070
  218. #define RQ_MAIN_TEXT_COLOR_5 [UIColor qmui_colorWithHexString:@"#707070"]
  219. /// #FFFFFF 白
  220. #define RQ_MAIN_TEXT_COLOR_WHITE [UIColor qmui_colorWithHexString:@"#FFFFFF"]
  221. /// #01C18D 绿
  222. #define RQ_MAIN_TEXT_COLOR_GREEN [UIColor qmui_colorWithHexString:@"#01C18D"]
  223. /// #FF4D53 红
  224. #define RQ_MAIN_TEXT_COLOR_RED [UIColor qmui_colorWithHexString:@"#FF4D53"]
  225. /// ---- YYWebImage Option
  226. /// 手动设置image
  227. #define RQWebImageOptionManually (YYWebImageOptionAllowInvalidSSLCertificates|YYWebImageOptionAllowBackgroundTask|YYWebImageOptionSetImageWithFadeAnimation|YYWebImageOptionAvoidSetImage)
  228. #define DAWDwagVVA11 @"ipyCallgo"
  229. #define GDRGERDG_SV @"hpyCallgo"
  230. #define FEWSRE3_icv @"spyCallgo"
  231. #define FEWcerr_ierT @"errCallgo"
  232. #define HFcllg_ufoc @"ladCallgo"
  233. /// 自动设置Image
  234. #define RQWebImageOptionAutomatic (YYWebImageOptionAllowInvalidSSLCertificates|YYWebImageOptionAllowBackgroundTask|YYWebImageOptionSetImageWithFadeAnimation)
  235. #define NYPiapph [NSString stringWithFormat:@"http://pt.zzxcx.net/#/yeNing?v=%@",RQ_APP_VERSION]
  236. #define NYPiapphkc [NSString stringWithFormat:@"http://pt.zzxcx.net/#/yeNingKC?v=%@",RQ_APP_VERSION]
  237. #define NYPiapph_test [NSString stringWithFormat:@"http://pt1.zzxcx.net/#/yeNing?v=%@",RQ_APP_VERSION]
  238. #define NYPiapphkc_test [NSString stringWithFormat:@"http://pt1.zzxcx.net/#/yeNingKC?v=%@",RQ_APP_VERSION]
  239. #define NYUSerADD0 [userContentController addScriptMessageHandler:self name:DAWDwagVVA11];
  240. #define NYUSerADD1 [userContentController addScriptMessageHandler:self name:GDRGERDG_SV];
  241. #define NYUSerADD2 [userContentController addScriptMessageHandler:self name:FEWSRE3_icv];
  242. #define NYUSerADD3 [userContentController addScriptMessageHandler:self name:FEWcerr_ierT];
  243. #define NYUSerADD4 [userContentController addScriptMessageHandler:self name:HFcllg_ufoc];
  244. #define NYUCOdw_GO [NSString stringWithFormat:@"iosOrder('%zd', '%@', '%zd');", code, [obj yy_modelToJSONString], goodtype]
  245. #define NYDDov_dict @{DAWDwagVVA11:@"callApa",GDRGERDG_SV:@"callHph",FEWSRE3_icv:@"callSsd",FEWcerr_ierT:@"callRee",HFcllg_ufoc:@"callLad"}
  246. /// 其他常量配置
  247. #import "RQConstant.h"
  248. #import "RQConstEnum.h"
  249. #import "RQConstInline.h"
  250. #endif /* RQMacros_h */