123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- //
- // ChatCacheFileUtil.m
- // NewMC
- //
- // Created by 话语科技 on 12-10-25.
- //
- //
- #import "ChatCacheFileUtil.h"
- NSString *const myUSERID=@"myUSERID";
- @implementation ChatCacheFileUtil
- static ChatCacheFileUtil *sharedInstance;
- + (ChatCacheFileUtil*)sharedInstance
- {
- if (sharedInstance==nil) {
- sharedInstance = [[ChatCacheFileUtil alloc] init];
- }
- return sharedInstance;
- }
- - (id)init
- {
- return [super init];
- }
- - (NSString*)userDocPath{
- NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
- NSString *userFolderPath = [[paths objectAtIndex:0] stringByAppendingPathComponent:[NSString stringWithFormat:@"%@/",MY_USER_ID]];
- NSFileManager *fileManager = [NSFileManager defaultManager];
- if (![fileManager fileExistsAtPath:userFolderPath]) {
- [fileManager createDirectoryAtPath:userFolderPath withIntermediateDirectories:YES attributes:nil error:nil];
- }
- return userFolderPath;
- }
- - (BOOL) deleteWithContentPath:(NSString *)thePath{
- NSError *error=nil;
- NSFileManager *fileManager = [NSFileManager defaultManager];
- if ([fileManager fileExistsAtPath:thePath]) {
- [fileManager removeItemAtPath:thePath error:&error];
- }
- if (error) {
- NSLog(@"删除文件时出现问题:%@",[error localizedDescription]);
- return NO;
- }
- return YES;
- }
- - (NSString*)chatCachePathWithFriendId:(NSString*)theFriendId andType:(NSInteger)theType
- {
- NSString *userChatFolderPath = [[self userDocPath] stringByAppendingPathComponent:[NSString stringWithFormat:@"chatLog/%@/",theFriendId]];
- switch (theType) {
- case 1:
- userChatFolderPath = [userChatFolderPath stringByAppendingPathComponent:@"voice/"];
- break;
- case 2:
- userChatFolderPath = [userChatFolderPath stringByAppendingPathComponent:@"image/"];
- break;
- default:
- break;
- }
- NSFileManager *fileManager = [NSFileManager defaultManager];
- if (![fileManager fileExistsAtPath:userChatFolderPath]) {
- [fileManager createDirectoryAtPath:userChatFolderPath withIntermediateDirectories:YES attributes:nil error:nil];
- }
- return userChatFolderPath;
- }
- - (void)deleteFriendChatCacheWithFriendId:(NSString*)theFriendId
- {
- NSString *userChatFolderPath = [[self userDocPath] stringByAppendingPathComponent:[NSString stringWithFormat:@"chatLog/%@/",theFriendId]];
-
- [[NSFileManager defaultManager] removeItemAtPath:userChatFolderPath error:nil];
- }
- - (void)deleteAllFriendChatDoc
- {
- NSString *userChatFolderPath = [[self userDocPath] stringByAppendingPathComponent:[NSString stringWithFormat:@"chatLog/"]];
-
- [[NSFileManager defaultManager] removeItemAtPath:userChatFolderPath error:nil];
-
- }
- @end
|