我有使用以下代码的第三方项目此代码不是全部,但它在应用程序包中写入大文件(比如记录)如何找到该文件?
NSError *audioSessionError = nil;
AVAudioSession *audioSession= [AVAudioSession sharedInstance];
[audioSession setCategory:AVAudioSessionCategoryPlayAndRecord error:&audioSessionError];
[audioSession setMode:AVAudioSessionModeDefault error:&audioSessionError];
[audioSession setPreferredSampleRate:16000.0f error:&audioSessionError];
[audioSession setPreferredInputNumberOfChannels:1 error:&audioSessionError];
[audioSession setActive:TRUE error:&audioSessionError];
_sampleRate= [audioSession sampleRate];
// make a capture session that uses the audio session
_captureSession = [[AVCaptureSession alloc]init];
_captureSession.sessionPreset = AVCaptureSessionPreset640x480;
_captureSession.automaticallyConfiguresApplicationAudioSession= NO;
_startTimeMS = [[NSDate date] timeIntervalSince1970] * 1000;
dispatch_queue_t videoQueue = dispatch_queue_create("smmaProcessingQueueVideo", NULL);
[_videoOutput setSampleBufferDelegate:self queue:videoQueue];
dispatch_queue_t audioQueue = dispatch_queue_create("smmaProcessingQueueAudio", NULL);
[_audioOutput setSampleBufferDelegate:self queue:audioQueue];
相同的视频代码,现在,此代码在应用程序中写入太大的文件(最多2 GB)。音频+视频,
我想找到&删除该文件。我试过
NSString *appFolderPath = [[NSBundle mainBundle] resourcePath];
NSFileManager *fileManager = [NSFileManager defaultManager];
NSLog(@"App Directory is: %@", appFolderPath);
NSLog(@"Directory Contents:\n%@", [fileManager directoryContentsAtPath: appFolderPath]);
怎么做?任何帮助都会非常感激。
答案 0 :(得分:2)
您可以清除temp directory
,
NSArray* tmpDirectory = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:NSTemporaryDirectory() error:NULL];
for (NSString *file in tmpDirectory) {
BOOL suc = [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@%@", NSTemporaryDirectory(), file] error:NULL];
if (suc) {
NSLog(@"done");
}
NSLog(@"file : %@%@",NSTemporaryDirectory(), file);
}
您可以清除cachedirectory
喜欢,
dirPaths = NSSearchPathForDirectoriesInDomains(
NSCachesDirectory, NSUserDomainMask, YES);
docsDir = [dirPaths objectAtIndex:0];
NSFileManager *manager1 = [NSFileManager defaultManager];
NSArray *filesArDirectory1 = [manager contentsOfDirectoryAtPath:docsDir error:nil];
NSError *err1;
for (NSString *file2 in filesArDirectory1) {
BOOL success = [manager1 removeItemAtPath:[NSString stringWithFormat:@"%@%@", docsDir,file2] error:&err1];
if (!success || err1) {
NSLog(@"error description : %@",[err1 localizedDescription]);
NSLog(@"failed2");
}
else{
NSLog(@"Success2");
}
NSLog(@"files : %@",file2);
}
如果存储数据,请尝试清除此目录。检查您的文档目录是否存储了大数据,然后您还需要对其进行管理。
希望这会有所帮助:)