CWFlieManager.m 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. //
  2. // CWFlieManager.m
  3. // QQVoiceDemo
  4. //
  5. // Created by chavez on 2017/10/13.
  6. // Copyright © 2017年 陈旺. All rights reserved.
  7. //
  8. #import "CWFlieManager.h"
  9. @implementation CWFlieManager
  10. singtonImplement(CWFlieManager);
  11. + (NSString *)CWFolderPath {
  12. NSString *documentDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
  13. NSString *cwFolderPath = [NSString stringWithFormat:@"%@/CWVoice",documentDir];
  14. BOOL isExist = [[NSFileManager defaultManager]fileExistsAtPath:cwFolderPath];
  15. if (!isExist) {
  16. [[NSFileManager defaultManager] createDirectoryAtPath:cwFolderPath withIntermediateDirectories:YES attributes:nil error:nil];
  17. }
  18. return cwFolderPath;
  19. }
  20. + (NSString *)soundTouchSavePathWithFileName:(NSString *)fileName {
  21. // NSString *fileName = [self fileName];
  22. NSString *wavfilepath = [NSString stringWithFormat:@"%@/SoundTouch",[CWFlieManager CWFolderPath]];
  23. NSString *writeFilePath = [NSString stringWithFormat:@"%@/%@",wavfilepath, fileName];
  24. BOOL isExist = [[NSFileManager defaultManager] fileExistsAtPath:writeFilePath];
  25. if (isExist) {
  26. //如果存在则移除 以防止 文件冲突
  27. // NSError *err = nil;
  28. [CWFlieManager removeFile:writeFilePath];
  29. // [[NSFileManager defaultManager] removeItemAtPath:writeFilePath error:&err];
  30. }
  31. BOOL isExistDic = [[NSFileManager defaultManager] fileExistsAtPath:wavfilepath];
  32. if (!isExistDic) {
  33. [[NSFileManager defaultManager] createDirectoryAtPath:wavfilepath withIntermediateDirectories:YES attributes:nil error:nil];
  34. }
  35. return writeFilePath;
  36. }
  37. + (NSString *)fileName {
  38. NSString *fileName = [NSString stringWithFormat:@"CWVoice%lld.wav",(long long)[NSDate timeIntervalSinceReferenceDate]];
  39. return fileName;
  40. }
  41. + (NSString *)filePath {
  42. NSString *path = [CWFlieManager CWFolderPath];
  43. NSString *fileName = [CWFlieManager fileName];
  44. return [path stringByAppendingPathComponent:fileName];
  45. }
  46. + (void)removeFile:(NSString *)filePath{
  47. [[NSFileManager defaultManager] removeItemAtPath:filePath error:nil];
  48. }
  49. @end