IM模块-缓存图片视频简单工具类
来源:互联网 发布:ubuntu 丢失windows 编辑:程序博客网 时间:2024/06/17 01:50
参考资料:
[简书地址](http://www.jianshu.com/users/23d0ae412e19/latest_articles)
#import "CacheHelper.h"@implementation CacheHelper+ (instancetype)sharedInstance{ static id _sharedInstance = nil; static dispatch_once_t oncePredicate; dispatch_once(&oncePredicate, ^{ _sharedInstance = [[self alloc] init]; }); return _sharedInstance;}- (void)saveMediaTypeWithMediaType:(MessageBodyType)messageBodyType FileData:(NSData *)data completion:(void (^)(NSString *mediaPath))completion{ NSString *mediaPath = nil; switch (messageBodyType) { case MessageBodyTypePhoto:{ // 照片 mediaPath = [self savePathFormediaType:MessageBodyTypePhoto]; break; } case MessageBodyTypeVideo:{//视频 mediaPath = [self savePathFormediaType:MessageBodyTypeVideo]; break; } case MessageBodyTypeVoice:{//录音 mediaPath = [self savePathFormediaType:MessageBodyTypeVoice]; break; } default: break; } // 这个路径只能是文件,才能输入。 如果是文件夹,将不会被创建。 [data writeToFile:mediaPath atomically:YES]; completion ? completion(mediaPath) : nil;}/** * Description: 保存数据 * * @param mediaType <#mediaType description#> * * @return <#return value description#> */- (NSString *)savePathFormediaType:(MessageBodyType)mediaType{ NSArray *pathArray = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *path = pathArray.firstObject; NSDate *date = [[NSDate alloc]init]; NSDateFormatter *formatter = [[NSDateFormatter alloc]init]; formatter.dateFormat = @"YYYY-MM-dd"; NSString *timeStr = [formatter stringFromDate:date]; NSString *typeStr = nil; switch (mediaType) { case MessageBodyTypePhoto:{ typeStr = [NSString stringWithFormat:@"%d.png",arc4random_uniform(1000)]; break; } case MessageBodyTypeVideo:{ typeStr = @"video.mov"; break; } case MessageBodyTypeVoice:{ typeStr = @"voice.m4a"; break; } default: break; } path = [[path stringByAppendingPathComponent:timeStr] stringByAppendingString:typeStr]; return path;}@end
0 0
- IM模块-缓存图片视频简单工具类
- 图片缓存工具类
- 图片缓存工具类
- 图片缓存工具类
- 图片三级缓存工具类
- 图片缓存的工具类
- IM模块--gif图片显示
- IM模块-UiCollectionView列表显示气泡图片
- 图片加载的缓存工具类
- 图片,视频上传工具
- 简单的图片加载缓存类
- [简单易懂]VideoCacheView使用解析,强大的视频缓存类
- 简单的图片处理工具类
- 通用工具类-异步加载图片&缓存提取
- android中图片内存缓存的工具类的实现
- Android 图片三级缓存机制工具类封装
- Android 图片三级缓存机制工具类封装
- 图片相关操作的工具类 下载 ,缓存到文件
- 关于数论以及部分其他学习内容总和
- 导入Excel方式汇总--第一种
- android 数据安全中常用的加密算法 AES
- 虚函数表
- Android MVPBuilder第三篇[GreenDao]
- IM模块-缓存图片视频简单工具类
- 点赞+1 效果
- AngularJS常用服务($http、$location、$sce等)
- onSenUI 常用UI组件 笔记
- js的原型链
- LINQ分页和排序,skip和Take 用法
- 微服务架构下,如何实现分布式跟踪?
- C# 怎么将byte字节拼接成uint
- 985的数学难题