// // PCSTools.m // sampleSDK // // Created by 王昭威 on 2023/1/15. // #import "PCSBaseViewController.h" #import "PCSTools.h" #import "OperationNodeProtocol.h" #import "QuitMultipleModeAlertViewController.h" #import "SDKParameters.h" #import "DBManager.h" #import "LenzSDKConstant.h" #import "LenzCachedResourceModel.h" const NSNotificationName LenzSDKNotificationDiskIsFull = @"LENZ_SDK_NOTIFICATION_DISK_IS_FULL"; const NSNotificationName CameraNotificationNotPermission = @"CameraNotificationNotPermission"; const NSNotificationName MicrophoneNotificationNotPermission = @"MicrophoneNotificationNotPermission"; inline CGFloat dgree_2_rad(CGFloat dgree){ return dgree / 180.0 * M_PI; } void showAlertToDiscardCachesWithTitle(id node, NSString* title, NSString* description, WillQuitCompletionBlockType block){ id curr = node; if(curr.controller == nil){ return; } if ([SDKParameters shared].retainedMode == SDK_DATA_RETAINED_CLEAR) { block(); } else if([SDKParameters shared].retainedMode == SDK_DATA_RETAINED_USER_CONFIRM && [curr respondsToSelector:@selector(numberOfCaches)] && curr.numberOfCaches > 0){ [QuitMultipleModeAlertViewController show: node.controller withSaveButtonCallBack:^(QuitMultipleModeAlertViewController * _Nonnull alertController) { [alertController dismissViewControllerAnimated:NO completion:^{}]; block(); } discardButtonCallBack:^(QuitMultipleModeAlertViewController * _Nonnull alertController) { if([curr respondsToSelector:@selector(cleanOnCompleted:)]){ [curr cleanOnCompleted:^{ [alertController dismissViewControllerAnimated:NO completion:^{}]; block(); }]; } }]; } else{ block(); } } @implementation PCSTools - (void)cleanDiskCache{ PCSTools* tool = [PCSTools shared]; LenzDBManager* dbMgr = [LenzDBManager shared]; NSArray* arr = [dbMgr fetchAll]; NSMutableArray* invalids = [NSMutableArray array]; NSFileManager* fileMgr = [NSFileManager defaultManager]; [arr enumerateObjectsUsingBlock:^(LenzCachedResourceModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { switch (obj.type) { case SDKCameraCapturedResourceIndexMovie: { NSURL* desUrl = [tool.moviesDir URLByAppendingPathComponent: obj.name isDirectory:NO]; NSError* err = nil; if([fileMgr fileExistsAtPath:desUrl.path] && [fileMgr removeItemAtURL:desUrl error:&err]){ [invalids addObject:obj]; } else if(![fileMgr fileExistsAtPath:desUrl.path]){ [invalids addObject:obj]; } } break; case SDKCameraCapturedResourceIndexPhoto: { NSString* path = [tool imagePathByName:obj.name]; NSError* err = nil; if([fileMgr fileExistsAtPath:path] && [fileMgr removeItemAtPath:path error:&err]){ [invalids addObject:obj]; } else if(![fileMgr removeItemAtPath:path error:&err]){ [invalids addObject:obj]; } } break; default: break; } }]; [dbMgr deleteModels:invalids]; } - (NSString *)mainStoryboardName{ return @"VC"; } + (PCSTools *)shared{ static PCSTools* tool = nil; static dispatch_once_t token; dispatch_once(&token, ^{ tool = [[self alloc] init]; }); return tool; } - (NSString *)documentPath{ NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES); NSString *path = [paths objectAtIndex:0]; return path; } - (NSString *)tmpPath{ NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory,NSUserDomainMask,YES); NSString *path = [paths objectAtIndex:0]; return path; } - (NSURL *)moviesDir{ return [[NSURL fileURLWithPath:self.tmpPath] URLByAppendingPathComponent:@"movies" isDirectory:YES]; } - (NSString*)imagePathByName: (NSString*)name{ NSString* tmpPath = [PCSTools shared].tmpPath; return [tmpPath stringByAppendingPathComponent:name]; } - (NSString *)libraryPath{ NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory,NSUserDomainMask,YES); NSString *path = [paths objectAtIndex:0]; return path; } //+ (NSBundle*)resourceBundle{ // NSBundle* classBundle = [NSBundle bundleForClass:self]; // NSBundle* resourceBundle = [classBundle URLForResource:@"LenzCameraNativeModuleForRN" withExtension:@"bundle"]; // return resourceBundle; //} + (NSBundle*)sdkBundle{ NSBundle* classBundle = [NSBundle bundleForClass:self]; NSURL* url = [classBundle URLForResource:@"LenzCameraNativeModuleForRN" withExtension:@"bundle"]; if(url == nil){ return nil; } NSBundle* resourceBundle = [NSBundle bundleWithURL:url]; return resourceBundle; return [NSBundle bundleWithIdentifier:@"LenzCameraNativeModuleForRN"]; } @end