PCSTools.m 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. //
  2. // PCSTools.m
  3. // sampleSDK
  4. //
  5. // Created by 王昭威 on 2023/1/15.
  6. //
  7. #import "PCSBaseViewController.h"
  8. #import "PCSTools.h"
  9. #import "OperationNodeProtocol.h"
  10. #import "QuitMultipleModeAlertViewController.h"
  11. #import "SDKParameters.h"
  12. #import "LenzSDKConstant.h"
  13. #import "LenzCachedResourceModel.h"
  14. const NSNotificationName LenzSDKNotificationDiskIsFull = @"LENZ_SDK_NOTIFICATION_DISK_IS_FULL";
  15. const NSNotificationName CameraNotificationNotPermission = @"CameraNotificationNotPermission";
  16. const NSNotificationName MicrophoneNotificationNotPermission = @"MicrophoneNotificationNotPermission";
  17. inline CGFloat dgree_2_rad(CGFloat dgree){
  18. return dgree / 180.0 * M_PI;
  19. }
  20. void showAlertToDiscardCachesWithTitle(id<OperationNodeProtocol> node, NSString* title, NSString* description, WillQuitCompletionBlockType block){
  21. id<OperationNodeProtocol> curr = node;
  22. if(curr.controller == nil){
  23. return;
  24. }
  25. if ([SDKParameters shared].retainedMode == SDK_DATA_RETAINED_CLEAR) {
  26. block();
  27. }
  28. else if([SDKParameters shared].retainedMode == SDK_DATA_RETAINED_USER_CONFIRM && [curr respondsToSelector:@selector(numberOfCaches)] && curr.numberOfCaches > 0){
  29. [QuitMultipleModeAlertViewController show: node.controller withSaveButtonCallBack:^(QuitMultipleModeAlertViewController * _Nonnull alertController) {
  30. [alertController dismissViewControllerAnimated:NO completion:^{}];
  31. block();
  32. } discardButtonCallBack:^(QuitMultipleModeAlertViewController * _Nonnull alertController) {
  33. if([curr respondsToSelector:@selector(cleanOnCompleted:)]){
  34. [curr cleanOnCompleted:^{
  35. [alertController dismissViewControllerAnimated:NO completion:^{}];
  36. block();
  37. }];
  38. }
  39. }];
  40. }
  41. else{
  42. block();
  43. }
  44. }
  45. @implementation PCSTools
  46. - (void)cleanDiskCache{
  47. }
  48. - (NSString *)mainStoryboardName{
  49. return @"VC";
  50. }
  51. + (PCSTools *)shared{
  52. static PCSTools* tool = nil;
  53. static dispatch_once_t token;
  54. dispatch_once(&token, ^{
  55. tool = [[self alloc] init];
  56. });
  57. return tool;
  58. }
  59. - (NSString *)documentPath{
  60. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
  61. NSString *path = [paths objectAtIndex:0];
  62. return path;
  63. }
  64. - (NSString *)tmpPath{
  65. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory,NSUserDomainMask,YES);
  66. NSString *path = [paths objectAtIndex:0];
  67. return path;
  68. }
  69. - (NSURL *)moviesDir{
  70. return [[NSURL fileURLWithPath:self.tmpPath] URLByAppendingPathComponent:@"movies" isDirectory:YES];
  71. }
  72. - (NSString*)imagePathByName: (NSString*)name{
  73. NSString* tmpPath = [PCSTools shared].tmpPath;
  74. return [tmpPath stringByAppendingPathComponent:name];
  75. }
  76. - (NSString *)libraryPath{
  77. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory,NSUserDomainMask,YES);
  78. NSString *path = [paths objectAtIndex:0];
  79. return path;
  80. }
  81. //+ (NSBundle*)resourceBundle{
  82. // NSBundle* classBundle = [NSBundle bundleForClass:self];
  83. // NSBundle* resourceBundle = [classBundle URLForResource:@"LenzCameraNativeModuleForRN" withExtension:@"bundle"];
  84. // return resourceBundle;
  85. //}
  86. + (NSBundle*)sdkBundle{
  87. NSBundle* classBundle = [NSBundle bundleForClass:self];
  88. NSURL* url = [classBundle URLForResource:@"LenzCameraNativeModuleForRN" withExtension:@"bundle"];
  89. if(url == nil){
  90. return nil;
  91. }
  92. NSBundle* resourceBundle = [NSBundle bundleWithURL:url];
  93. return resourceBundle;
  94. return [NSBundle bundleWithIdentifier:@"LenzCameraNativeModuleForRN"];
  95. }
  96. @end