2
0

LBXPermission.m 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. //
  2. // LBXPermission.m
  3. // LBXKits
  4. //
  5. // Created by lbx on 2017/9/7.
  6. // Copyright © 2017年 lbx. All rights reserved.
  7. //
  8. #import "LBXPermission.h"
  9. #import <UIKit/UIKit.h>
  10. #import <objc/runtime.h>
  11. #import <objc/message.h>
  12. typedef void(^completionPermissionHandler)(BOOL granted,BOOL firstTime);
  13. @implementation LBXPermission
  14. + (BOOL)authorizedWithType:(LBXPermissionType)type
  15. {
  16. SEL sel = NSSelectorFromString(@"authorized");
  17. NSString *strClass = nil;
  18. switch (type) {
  19. case LBXPermissionType_Camera:
  20. strClass = @"LBXPermissionCamera";
  21. break;
  22. case LBXPermissionType_Photos:
  23. strClass = @"LBXPermissionPhotos";
  24. break;
  25. default:
  26. break;
  27. }
  28. if (strClass) {
  29. BOOL ret = ((BOOL *(*)(id,SEL))objc_msgSend)( NSClassFromString(strClass), sel);
  30. return ret;
  31. }
  32. return NO;
  33. }
  34. + (void)authorizeWithType:(LBXPermissionType)type completion:(void(^)(BOOL granted,BOOL firstTime))completion
  35. {
  36. NSString *strClass = nil;
  37. switch (type) {
  38. case LBXPermissionType_Camera:
  39. strClass = @"LBXPermissionCamera";
  40. break;
  41. case LBXPermissionType_Photos:
  42. strClass = @"LBXPermissionPhotos";
  43. break;
  44. default:
  45. break;
  46. }
  47. if (strClass)
  48. {
  49. SEL sel = NSSelectorFromString(@"authorizeWithCompletion:");
  50. ((void(*)(id,SEL, completionPermissionHandler))objc_msgSend)(NSClassFromString(strClass),sel, completion);
  51. }
  52. }
  53. @end