洛阳学员端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

111 lines
3.9 KiB

7 months ago
  1. //
  2. // APBUtils.h
  3. // BioAuthEngine
  4. //
  5. // Created by richard on 27/08/2017.
  6. // Copyright © 2017 DTF. All rights reserved.
  7. //
  8. #import <Foundation/Foundation.h>
  9. #import <AVFoundation/AVFoundation.h>
  10. #include <sys/param.h>
  11. #include <sys/mount.h>
  12. #define SCREEN_WIDTH [[UIScreen mainScreen]bounds].size.width //屏幕宽度
  13. #define SCREEN_HEIGHT [[UIScreen mainScreen]bounds].size.height //屏幕高度
  14. //获取document目录
  15. #define DOCUMENT_PATH [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"]
  16. //资源文件目录
  17. #define ASSET_PATH [DOCUMENT_PATH stringByAppendingPathComponent:@"BioAuth"]
  18. //返回不为nil的string
  19. #define NONE_NIL_STRING(str) (str ? str : @"")
  20. #define SafeRelease(obj) if(obj){obj=nil;}
  21. //主线程同步操作
  22. #define SYNC_MAINTHREAD_BEGIN [APBUtils APBMainThread:^{
  23. #define SYNC_MAINTHREAD_END }];
  24. //pipeInfo线程安全操作
  25. static NSString *const kAPBPipeInfoMutexToken = @"";
  26. static id __apb_thread_safe_object_for_key(NSMutableDictionary *pipeInfo, NSString *key){
  27. id ret;
  28. @synchronized(kAPBPipeInfoMutexToken){
  29. if ([pipeInfo isKindOfClass:[NSMutableDictionary class]] && [pipeInfo objectForKey: key]) {
  30. ret = [pipeInfo objectForKey:key];
  31. }
  32. }
  33. return ret;
  34. }
  35. //从pipeInfo中获取Object,线程安全
  36. #define THREAD_SAFE_OBJECT_FOR_KEY(pipeInfo, key) __apb_thread_safe_object_for_key(pipeInfo, key)
  37. //向pipeInfo中添加或修改Object,线程安全
  38. #define THREAD_SAFE_SET_OBJECT_FOR_KEY(pipeInfo, key, value) \
  39. @synchronized(kAPBPipeInfoMutexToken){ \
  40. if ([pipeInfo isKindOfClass:[NSMutableDictionary class]] && key && value) { \
  41. [pipeInfo setObject:value forKey:key];}}
  42. //删除PipeInfo中某个Object,线程安全
  43. #define THREAD_SAFE_REMOVE_OBJECT_FOR_KEY(pipeInfo, key) \
  44. @synchronized(kAPBPipeInfoMutexToken){ \
  45. if ([pipeInfo isKindOfClass:[NSMutableDictionary class]] && [pipeInfo objectForKey: key]) { \
  46. [pipeInfo removeObjectForKey: key];}}
  47. //将dict中对应value增加1
  48. #define INCREASE_BY_ONE(pipeInfo, key){ \
  49. NSInteger num = [[pipeInfo objectForKey:key]integerValue]+1; \
  50. THREAD_SAFE_SET_OBJECT_FOR_KEY(pipeInfo, key, [NSNumber numberWithInteger:num]);}
  51. //将dict中对应value减1
  52. #define DECREASE_BY_ONE(pipeInfo, key){ \
  53. NSInteger num = [[pipeInfo objectForKey:key]integerValue]-1; \
  54. THREAD_SAFE_SET_OBJECT_FOR_KEY(pipeInfo, key, [NSNumber numberWithInteger:--num]);}
  55. #define LOCK(locker, ...) dispatch_semaphore_wait(locker, DISPATCH_TIME_FOREVER); \
  56. __VA_ARGS__; \
  57. dispatch_semaphore_signal(locker);
  58. @interface APBUtils : NSObject
  59. + (NSString *)MD5WithData:(NSData *)data;
  60. + (NSString *)randomString:(NSInteger)len;
  61. + (BOOL)isWifi;
  62. /**
  63. * 线
  64. */
  65. + (void)APBMainThread:(dispatch_block_t)block;
  66. + (NSDictionary *)dictionaryWithJsonString:(NSString *)jsonString;
  67. + (NSString*)convertToJSONString:(NSDictionary *)infoDict;
  68. + (NSString *)currentLanguage;
  69. + (NSString *)localizedStringForKey:(NSString *)key inBundle:(NSString *)bundle;
  70. + (NSString *)localizedStringForKey:(NSString *)key;
  71. + (long long)getTotalDiskSize;
  72. + (long long)getAvailableDiskSize;
  73. + (NSString*)deviceVersion;
  74. + (NSString *)osVersion;
  75. + (NSString *)appName;
  76. + (NSString *)appVersion;
  77. + (CMVideoDimensions)maxResolution:(AVCaptureDevicePosition) position;
  78. @end