Commit d13bec6b821e532beb7144167657e6f1771e3d85

Authored by guoruipeng
1 parent 66975480

no message

CNLiveBusinessTools/Classes/CNLiveBusinessTools.h
@@ -61,6 +61,42 @@ typedef NS_ENUM(NSInteger, CNFileType) { @@ -61,6 +61,42 @@ typedef NS_ENUM(NSInteger, CNFileType) {
61 //sha1签名 61 //sha1签名
62 + (NSMutableDictionary *_Nullable)encryptionSignWithParameter:(NSMutableDictionary *_Nullable)parameter encryptionKey:(NSString *_Nullable)encryptionKey; 62 + (NSMutableDictionary *_Nullable)encryptionSignWithParameter:(NSMutableDictionary *_Nullable)parameter encryptionKey:(NSString *_Nullable)encryptionKey;
63 #pragma mark -- 63 #pragma mark --
  64 +#pragma mark -- 缓存
  65 +/**
  66 + GIF表情存放位置
  67 + @return 地址
  68 + */
  69 ++ (NSString *)newChatGifFacePath;
  70 +/**
  71 + @param userId 单聊为对方ID,群聊为群聊 ID,图片和视频存放位置
  72 + @return 地址
  73 + */
  74 ++ (NSString *)newChatFilePathByUserId:(NSString *)userId;
  75 +
  76 ++ (nullable NSString *)chatFileWithCachePathByUserId:(NSString *_Nonnull)userId;
  77 +
  78 +//用户ID
  79 ++ (nullable NSString *)chatFilePathByUserId:(NSString *_Nonnull)userId;
  80 +
  81 +/**
  82 + @param userId 单聊为对方ID,群聊为群聊 ID
  83 + @return 返回聊天发送的文件 所保存的文件夹地址
  84 + */
  85 ++ (NSString *)getChatFilesPathByUserId:(NSString *)userId;
  86 +
  87 +/**
  88 + 0
  89 + @param userId 单聊为对方ID,群聊为群聊 ID ,语音文件保存路径
  90 + */
  91 ++ (NSString *)audioChatFilePathByUserId:(NSString *)userId;
  92 +
  93 +/**
  94 + 聊天背景图图片地址
  95 +
  96 + @return file
  97 + */
  98 ++ (NSString *)chatBackgroupImagefilePath;
  99 +#pragma mark --
64 @end 100 @end
65 101
66 NS_ASSUME_NONNULL_END 102 NS_ASSUME_NONNULL_END
CNLiveBusinessTools/Classes/CNLiveBusinessTools.m
@@ -420,4 +420,197 @@ @@ -420,4 +420,197 @@
420 420
421 } 421 }
422 422
  423 +
  424 +/**
  425 + GIF表情存放位置
  426 + @return 地址
  427 + */
  428 ++ (NSString *)newChatGifFacePath{
  429 +
  430 + // NSHomeDirectory():应用程序目录, 在Documents文件夹下创建
  431 + NSString *tempName = [NSString stringWithFormat:@"Documents/%@/GifFace/Cache", CNUserShareModel.uid];
  432 +
  433 + NSString *filePath = [NSHomeDirectory() stringByAppendingPathComponent:tempName];
  434 +
  435 + NSFileManager *fileManager = [NSFileManager defaultManager];
  436 +
  437 + BOOL isDir = NO;
  438 +
  439 + // fileExistsAtPath 判断一个文件或目录是否有效,isDirectory判断是否一个目录
  440 + BOOL existed = [fileManager fileExistsAtPath:filePath isDirectory:&isDir];
  441 +
  442 + if ( !(isDir == YES && existed == YES) ) {
  443 +
  444 + // 在 tmp 目录下创建一个 temp 目录
  445 + [fileManager createDirectoryAtPath:filePath withIntermediateDirectories:YES attributes:nil error:nil];
  446 + }
  447 +
  448 + return filePath;
  449 +
  450 +}
  451 +/**
  452 + @param userId 单聊为对方ID,群聊为群聊 ID,图片和视频存放位置
  453 + @return 地址
  454 + */
  455 ++ (NSString *)newChatFilePathByUserId:(NSString *)userId{
  456 +
  457 + // NSHomeDirectory():应用程序目录, 在Documents文件夹下创建
  458 + NSString *tempName = [NSString stringWithFormat:@"Documents/%@/%@/imageorvideo", CNUserShareModel.uid, userId];
  459 +
  460 + NSString *filePath = [NSHomeDirectory() stringByAppendingPathComponent:tempName];
  461 +
  462 + NSFileManager *fileManager = [NSFileManager defaultManager];
  463 +
  464 + BOOL isDir = NO;
  465 +
  466 + // fileExistsAtPath 判断一个文件或目录是否有效,isDirectory判断是否一个目录
  467 + BOOL existed = [fileManager fileExistsAtPath:filePath isDirectory:&isDir];
  468 +
  469 + if ( !(isDir == YES && existed == YES) ) {
  470 +
  471 + // 在 tmp 目录下创建一个 temp 目录
  472 + [fileManager createDirectoryAtPath:filePath withIntermediateDirectories:YES attributes:nil error:nil];
  473 + }
  474 +
  475 + return filePath;
  476 +
  477 +}
  478 +
  479 ++ (nullable NSString *)chatFileWithCachePathByUserId:(NSString *_Nonnull)userId{
  480 + // NSHomeDirectory():应用程序目录, @"tmp/temp":在tmp文件夹下创建temp 文件夹
  481 + // NSString *tempName = [NSString stringWithFormat:@"cache/%@/%@", CNUserShareModel.uid, userId];
  482 +
  483 + NSString *filePath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory,NSUserDomainMask, YES) objectAtIndex:0]; //stringByAppendingPathComponent:tempName];
  484 +
  485 + NSFileManager *fileManager = [NSFileManager defaultManager];
  486 +
  487 + BOOL isDir = NO;
  488 +
  489 + // fileExistsAtPath 判断一个文件或目录是否有效,isDirectory判断是否一个目录
  490 + BOOL existed = [fileManager fileExistsAtPath:filePath isDirectory:&isDir];
  491 +
  492 + if ( !(isDir == YES && existed == YES) ) {
  493 +
  494 + // 在 tmp 目录下创建一个 temp 目录
  495 + [fileManager createDirectoryAtPath:filePath withIntermediateDirectories:YES attributes:nil error:nil];
  496 + }
  497 +
  498 + return filePath;
  499 +}
  500 +
  501 +//用户ID
  502 ++ (nullable NSString *)chatFilePathByUserId:(NSString *_Nonnull)userId{
  503 +
  504 + // NSHomeDirectory():应用程序目录, @"tmp/temp":在tmp文件夹下创建temp 文件夹
  505 + NSString *tempName = [NSString stringWithFormat:@"%@/",userId];
  506 +
  507 + NSString *filePath = [NSTemporaryDirectory() stringByAppendingPathComponent:tempName];
  508 +
  509 + NSFileManager *fileManager = [NSFileManager defaultManager];
  510 +
  511 + BOOL isDir = NO;
  512 +
  513 + // fileExistsAtPath 判断一个文件或目录是否有效,isDirectory判断是否一个目录
  514 + BOOL existed = [fileManager fileExistsAtPath:filePath isDirectory:&isDir];
  515 +
  516 + if ( !(isDir == YES && existed == YES) ) {
  517 +
  518 + // 在 temp 目录下创建一临时文件
  519 + [fileManager createDirectoryAtPath:filePath withIntermediateDirectories:YES attributes:nil error:nil];
  520 + }
  521 +
  522 + return filePath;
  523 +
  524 +}
  525 +
  526 +/**
  527 + @param userId 单聊为对方ID,群聊为群聊 ID
  528 + @return 返回聊天发送的文件 所保存的文件夹地址
  529 + */
  530 ++ (NSString *)getChatFilesPathByUserId:(NSString *)userId{
  531 + NSString *tempName = [NSString stringWithFormat:@"Documents/%@/%@/file", CNUserShareModel.uid, userId];
  532 +
  533 + NSString *filePath = [NSHomeDirectory() stringByAppendingPathComponent:tempName];
  534 +
  535 + NSFileManager *fileManager = [NSFileManager defaultManager];
  536 +
  537 + BOOL isDir = NO;
  538 +
  539 + // fileExistsAtPath 判断一个文件或目录是否有效,isDirectory判断是否一个目录
  540 + BOOL existed = [fileManager fileExistsAtPath:filePath isDirectory:&isDir];
  541 +
  542 + if ( !(isDir == YES && existed == YES) ) {
  543 +
  544 + // 在 Documents 目录下创建
  545 +
  546 + if ([fileManager createDirectoryAtPath:filePath withIntermediateDirectories:YES attributes:nil error:nil]) {
  547 + NSLog(@"创建聊天文件路径成功");
  548 + }
  549 + else
  550 + {
  551 + NSLog(@"聊天文件路径已经创建过");
  552 + }
  553 + }
  554 + return filePath;
  555 +}
  556 +
  557 +/**
  558 + 0
  559 + @param userId 单聊为对方ID,群聊为群聊 ID ,语音文件保存路径
  560 + */
  561 ++ (NSString *)audioChatFilePathByUserId:(NSString *)userId{
  562 + NSString *tempName = [NSString stringWithFormat:@"Documents/%@/%@/audio", CNUserShareModel.uid, userId];
  563 +
  564 + NSString *filePath = [NSHomeDirectory() stringByAppendingPathComponent:tempName];
  565 +
  566 + NSFileManager *fileManager = [NSFileManager defaultManager];
  567 +
  568 + BOOL isDir = NO;
  569 +
  570 + // fileExistsAtPath 判断一个文件或目录是否有效,isDirectory判断是否一个目录
  571 + BOOL existed = [fileManager fileExistsAtPath:filePath isDirectory:&isDir];
  572 +
  573 + if ( !(isDir == YES && existed == YES) ) {
  574 +
  575 + // 在 Documents 目录下创建
  576 +
  577 + if ([fileManager createDirectoryAtPath:filePath withIntermediateDirectories:YES attributes:nil error:nil]) {
  578 + NSLog(@"创建语音文件成功");
  579 + }
  580 + else
  581 + {
  582 + NSLog(@"语音文件已经存在");
  583 + }
  584 + }
  585 + return filePath;
  586 +}
  587 +
  588 +/**
  589 + 聊天背景图图片地址
  590 +
  591 + @return file
  592 + */
  593 ++ (NSString *)chatBackgroupImagefilePath{
  594 +
  595 + // NSHomeDirectory():应用程序目录, 在Documents文件夹下创建
  596 + NSString *tempName = [NSString stringWithFormat:@"Documents/%@/chatBackgroupImage", CNUserShareModel.uid];
  597 +
  598 + NSString *filePath = [NSHomeDirectory() stringByAppendingPathComponent:tempName];
  599 +
  600 + NSFileManager *fileManager = [NSFileManager defaultManager];
  601 +
  602 + BOOL isDir = NO;
  603 +
  604 + // fileExistsAtPath 判断一个文件或目录是否有效,isDirectory判断是否一个目录
  605 + BOOL existed = [fileManager fileExistsAtPath:filePath isDirectory:&isDir];
  606 +
  607 + if ( !(isDir == YES && existed == YES) ) {
  608 +
  609 + // 在 tmp 目录下创建一个 temp 目录
  610 + [fileManager createDirectoryAtPath:filePath withIntermediateDirectories:YES attributes:nil error:nil];
  611 + }
  612 +
  613 + return filePath;
  614 +
  615 +}
423 @end 616 @end